Often we will display many items with TableView, sometimes need to display pictures, but once from the server to take all the pictures to the user to waste traffic, the server is also a burden. It is best to load on demand, that is, when the user wants to browse for the item and then loads its picture.
-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: ( Nsindexpath *) indexpath { *image = [self getimageforcellatindexpath:indexpath]; // get pictures from the internet [Cell.imageview setimage:image];
This solves the problem of delayed loading, but when the network speed is slow, or the picture is large (assuming, although the figure in the cell is very small), you will notice that the program may lose its response to the user.
Reason is
UIImage *image = [self getimageforcellatindexpath:indexpath];
This method can take a lot of time to process the main thread.
So the response to the user has been lost.
So you need to do the following rewrite:
-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: ( Nsindexpath *) indexpath { [self performselectorinbackground: @selector ( Updateimageforcellatindexpath:)]; } -(void) Updateimageforcellatindexpath: (Nsindexpath *) indexpath { @autoReleasePool { c11/>*image = [self getimageforcellatindexpath:indexpath]; *cell = [Self.tableview cellforrowatindexpath:indexpath]; [Cell.imageview performselectoronmainthread: @selector (setimage:) withobject:image waituntildone:no];
How to solve image delay loading in iOS development in TableView