这是我的代码,试图用字符串创建 NSMutable 数组,然后将它们存储在对象属性中。NSArray *photos 有效,但 NSMUtableArray thumbImageURL 无效。当我 NSLog 用于调试目的时,它为空。请帮助,这让我很烦恼,找不到解决方案。我也懒惰地实例化,所以没有理由它不会在内存中分配。
惰性实例化:
-(void)setThumbImageURL:(NSMutableArray *)thumbImageURL
{
if (!_thumbImageURL) _thumbImageURL=[[NSMutableArray alloc] initWithCapacity:50];
_thumbImageURL=thumbImageURL;
}
我的代码:
[PXRequest requestForPhotoFeature:PXAPIHelperPhotoFeaturePopular resultsPerPage:50 page:1 photoSizes:(PXPhotoModelSizeLarge | PXPhotoModelSizeThumbnail | PXPhotoModelSizeSmallThumbnail |PXPhotoModelSizeExtraLarge) sortOrder:PXAPIHelperSortOrderCreatedAt completion:^(NSDictionary *results, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (results) {
self.photos =[results valueForKey:@"photos"];
NSLog(@"%@",self.photos);
}
NSLog(@"\n\n\n\n\n\n\n\nSelf photos count : %lu",[self.photos count]);
for (int i=0; i<[self.photos count]; i++)
{
NSURL *thumbImageUrl= [NSURL URLWithString:[[[self.photos valueForKey:@"images"] [i] valueForKey:@"url"] firstObject]];
NSData *imageData=[NSData dataWithContentsOfURL:thumbImageUrl];
[self.thumbImageURL addObject:imageData];
self.largeImageURL[i]=[[[self.photos valueForKey:@"images"] [i] valueForKey:@"url"] lastObject];
}
NSLog(@"\n\n\n\n\n\n\n\nSelf Thum Image after : %@",self.thumbImageURL);
NSLog(@"\n\n\n\n\n\n\n\nSelf large Image after : %@n\n\n\n\n\n\n\n",self.largeImageURL);
}];