Reputation: 553
i have uitableview
with customer UitableViewcell
my cell hold in the Uiimageview
i use the Url
to load image to my UIimageView
so in the scroling in the tableview my app crashing
my code source :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ActusCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
NSDictionary *tmpDict = [_MyArray objectAtIndex:indexPath.row];
dispatch_async ( dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0ul), ^{
act_Image=[NSString stringWithFormat:@"http://www.exemple.com/act/%@%@",[tmpDict objectForKey:@"id"],@".jpeg"];
NSURL * imageURL = [ NSURL URLWithString :act_Image ];
NSData * imageDataUrl = [ NSData dataWithContentsOfURL : imageURL ];
dispatch_async ( dispatch_get_main_queue (), ^ {
[cell.myimage setImage:[UIImage imageWithData:imageDataUrl]];
});
});
return cell;
}
N.B :the image in the URl have size 1.2MB
Upvotes: 0
Views: 370
Reputation: 4040
The problem is caused by your dispatches. They're never cancelled.
You should look into starting to use NSOperation
and NSOperationQueue
when the cell is being reused, cancel the operation it was performing.
Upvotes: 0
Reputation: 2817
I think You should load image asynchronously and save that in cache.For that there is so many third party source available. I found this are the best of them-
1.https://github.com/nicklockwood/AsyncImageView 2.https://github.com/rs/SDWebImage
Upvotes: 1