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];
}
答案 0 :(得分:0)
更改:
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];
致:
[self.images addObject:@"http://farm6.staticflickr.com/5095/5426345292_40ec29d5ea.jpg"];
[self.images addObject:@"http://farm6.staticflickr.com/5095/5426345292_40ec29d5ea_s.jpg"];