Story Board : IBOutlet link Control
#import "FirstViewController.h"
@interface FirstViewController ()
@property (nonatomic, weak)IBOutlet UIImageView *imageView;
@property (nonatomic, weak)IBOutlet UIButton *btnChange;
@property (nonatomic, assign)int ibool;
@property (nonatomic, weak)IBOutlet UIActivityIndicatorView *indicatorView;
@end
@implementation FirstViewController
@synthesize imageView;
@synthesize ibool;
@synthesize btnChange;
@synthesize indicatorView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
ibool =0;
[indicatorView stopAnimating];
}
-(IBAction)actionChange:(id)sender{
ibool+=1;
[indicatorView startAnimating];
NSString *strurl;
if (ibool==1) {
strurl=@"http://images.apple.com/v/watch/b/overview/images/connect_large.jpg";
}else if(ibool==2){
strurl=@"http://images.apple.com/v/watch/b/overview/images/edition_large.jpg";
ibool=0;
}
NSURL *imageURL = [NSURL URLWithString:strurl];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
self.imageView.image = [UIImage imageWithData:imageData];
[indicatorView stopAnimating];
});
});
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- (void)notesOnDropbox
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// 1
NSURL *url = [Dropbox appRootURL];
// 2
NSURLSessionDataTask *dataTask =
[self.session dataTaskWithURL:url
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
if (!error) {
// TODO 1: More coming here!
// 1
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
if (httpResp.statusCode == 200) {
NSError *jsonError;
// 2
NSDictionary *notesJSON =
[NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&jsonError];
NSMutableArray *notesFound = [[NSMutableArray alloc] init];
if (!jsonError) {
// TODO 2: More coming here!
// 1
NSArray *contentsOfRootDirectory = notesJSON[@"contents"];
for (NSDictionary *data in contentsOfRootDirectory) {
if (![data[@"is_dir"] boolValue]) {
DBFile *note = [[DBFile alloc] initWithJSONData:data];
[notesFound addObject:note];
}
}
[notesFound sortUsingComparator:
^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2];
}];
self.notes = notesFound;
// 6
dispatch_async(dispatch_get_main_queue(), ^{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[self.tableView reloadData];
});
}
}
}
}];
// 3
[dataTask resume];
}
