Downloading pictures on the Internet is very slow, in order to not affect the experience, choose to load the image delay is a good way. A tableview list, left temporarily without a diagram
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (nsindexpath*) Indexpath
{
static NSString *cellidentifier = @ "MyCell";
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];
if (cell = = nil)
{
cell = [[[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle
Reuseidentifier:cellidentifier] autorelease];
Cell.selectionstyle = Uitableviewcellselectionstylenone;
}
Set up cell some data
Apprecord *apprecord = [Self.entries objectAtIndex:indexPath.row];
Cell.textLabel.text = Apprecord.appname;
Cell.detailTextLabel.text = apprecord.artist;
If no picture exists
if (!apprecord.appicon)
{
if (self.tableView.dragging = = no && self.tableView.decelerating = = no)//not in drag and deceleration, start downloading pictures
{
[Self Starticondownload:apprecord forindexpath:indexpath];
}
Set picture as a blank picture (Waiting for download)
Cell.imageView.image = [UIImage imagenamed:@ "Placeholder.png"];
}
If you have a picture
Else
{
Cell.imageView.image = Apprecord.appicon;
}
return cell;
}
The point is[Self Starticondownload:apprecord forindexpath:indexpath];
-(void) Starticondownload: (Apprecord *) Apprecord Forindexpath: (Nsindexpath *) Indexpath
{
Icondownloader *icondownloader = [imagedownloadsinprogress Objectforkey:indexpath];
if (Icondownloader = = nil)//is already in the download does not have to repeat the download, did not go down in the download
{
Icondownloader = [[Icondownloader alloc] init];
Icondownloader.apprecord = Apprecord;
Icondownloader.indexpathintableview = Indexpath;
Icondownloader.delegate = self;
[Imagedownloadsinprogress Setobject:icondownloader Forkey:indexpath];
[Icondownloader Startdownload];
[Icondownloader release];
}
}
Icondownloader is a download picture encapsulation class Key method: Icondownloader.delegate = self; [Icondownloader Startdownload]; One is a delegate, in the future tell the self download to complete the update picture one is their own method to start the network download picture delegate call method, reset the picture
-(void) Appimagedidload: (Nsindexpath *) Indexpath
{
Icondownloader *icondownloader = [imagedownloadsinprogress Objectforkey:indexpath];
if (icondownloader! = nil)
{
UITableViewCell *cell = [Self.tableViewcellForRowAtIndexPath:iconDownloader.indexPathInTableView];
Cell.imageView.image = IconDownloader.appRecord.appIcon;
}
}
Methods in the class Icondownloader
-(void) startdownload
{
Self.activedownload = [Nsmutabledata data];
Nsurlconnection *conn = [[Nsurlconnection alloc] Initwithrequest:
[Nsurlrequest Requestwithurl:
[Nsurl URLWithString:appRecord.imageURLString]] Delegate:self];
Self.imageconnection = conn;
[Conn release];
}
Last Nsurlconnectionthe delegate needs to be implemented by itself.
iOS Delay loading network pictures