i use code below download image, found code keep downloading never stop, can avoid it?
code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"appsearchcell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; cell.backgroundcolor = [uicolor orangecolor]; cell.imageview.image = nil; } #define kbgqueue dispatch_get_global_queue(dispatch_queue_priority_default, 0) dispatch_async(kbgqueue, ^{ nsstring *iconurl = [searchresultsiconurl objectatindex:indexpath.row]; nsdata *imagedata = [nsdata datawithcontentsofurl:[nsurl urlwithstring:iconurl]]; dispatch_async(dispatch_get_main_queue(), ^{ cell.imageview.image = [uiimage imagewithdata:imagedata]; [tableview reloadrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationnone]; }); }); return cell; }
first thing not want doing download in call. slow down loading of table.
loop calling "reloadrowsatindexpaths" going trigger cellforrowatindexpath
suggestion start download in viewdidload or viewwillappear method , update table without going loop.
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
Comments
Post a Comment