flickPhotosSearch
应该做评论的自我。图片行可以。如果我取消注释,它可以正常工作,但由于我需要它动态工作,我需要让 flickrPhotoSearch 做同样的事情。它将相同的信息保存到图像数组中,但是当它离开该方法时,它不再起作用。
[self flickrPhotosSearch:url];
/* self.images = [[NSMutableArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"http://farm6.staticflickr.com/5095/5426345292_40ec29d5ea.jpg", @"http://farm6.staticflickr.com/5095/5426345292_40ec29d5ea_s.jpg", nil], nil]; */
NSLog(@"%@", self.images);
}
return self;
}
-(void)flickrPhotosSearch:(NSURL *) url {
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *photos = [JSON objectForKey:@"photos"];
self.picturesOfLocations = [photos objectForKey:@"photo"];
for (NSDictionary * photo in self.picturesOfLocations ){
NSString* flickrfarmID = [photo objectForKey:@"farm"];
NSString* flickrServer = [photo objectForKey:@"server"];
NSString* flickrID = [photo objectForKey:@"id"];
NSString* flickrSecret = [photo objectForKey:@"secret"];
NSString *stringURLOriginalImage = [[NSString alloc] initWithFormat:@"http://farm%@.staticflickr.com/%@/%@_%@.jpg",flickrfarmID,flickrServer, flickrID,flickrSecret];
NSString *stringURLSmallImage = [[NSString alloc] initWithFormat:@"http://farm%@.staticflickr.com/%@/%@_%@_s.jpg",flickrfarmID,flickrServer, flickrID,flickrSecret];
[self.images addObject:[NSArray arrayWithObjects:stringURLOriginalImage,stringURLSmallImage, nil]];
NSLog(@"%@", self.images);
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];
}