Reputation: 85
I've written code that gathers images from JSON requests and attempts to add them to an NSMutableArray
to be used later in a table view. The problem is after adding the image objects to the array, the size of my NSMutableArray
is 0. Here is the relevant code:
@implementation example{
NSMutableArray *_placeImages;
}
-(void)viewDidLoad{
...
_placeImages = [[NSMutableArray alloc] init];
}
-(void)JsonQuery {
...
// Retrieve the results of the URL.
dispatch_async(kMyQueue, ^{
[self downloadImages];
[self performSelectorOnMainThread:@selector(reloadTableData) withObject:NULL waitUntilDone:YES];
});
}
-(void)downloadImages{
...
NSData* data = [NSData dataWithContentsOfURL: url];
UIImage* image = [UIImage imageWithData:data];
[_placeImages addObject:image];
}
Upvotes: 0
Views: 86
Reputation: 1086
you must alloc NSMutableArray first:
_placeImages = [[NSMutableArray alloc] init];
or you can using lazy init:
- (NSMutableArray *)placeImages
{
if (!_placeImages) {
_placeImages = [[NSMutableArray alloc] init];
}
return _placeImages
}
Upvotes: 3