How to avoid loop download image in cellForRowAtIndexPath?


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

Popular posts from this blog

Rogue - the old text based game. I can't find it!

RAID in Early 2009 Mac Pro

NBC Releases Summer Olympics iOS Apps, Offering Livestreaming of All 302 Events