iphone (UITableViewCell) loading pictures dynamically
http://developer.apple.com/library/ios/#samplecode/lazytableimages/introduction/intro.html
In fact, on the iphone is to realize the dynamic loading of the picture, in fact, it is not difficult, as long as the agent in the implementation of the method can be
First, declare the proxy used in the header file as
@interface xxx:uiviewcontroller<uiscrollviewdelegate>
And then implemented in. m
When scrolling stops, it gets the image information to display on the UITableViewCell.
-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate
{
if (!decelerate)
{
[Self loadimagesforonscreenrows];
}
}
-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView
{
[Self loadimagesforonscreenrows];
}
//
-(void) loadimagesforonscreenrows
{
if ([self.entries count] > 0)
{
Nsarray *visiblepaths = [Self.tableview indexpathsforvisiblerows];
For (Nsindexpath *indexpath in visiblepaths)
{
Apprecord *apprecord = [Self.entries objectAtIndex:indexPath.row];
if (!apprecord.appicon)//Avoid the app icon download if the app already have an icon
{
[Self Starticondownload:apprecord forindexpath:indexpath];
}
}
}
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
....//Initialize UITableView related information
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];
if (cell = = nil)
{
cell = [[[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle
Reuseidentifier:cellidentifier] autorelease];
Cell.selectionstyle = Uitableviewcellselectionstylenone;
}
.........
if (!apprecord.appicon)//When UITableViewCell has no image information
{
if (self.tableView.dragging = = no && self.tableView.decelerating = = no)// When table stops slipping, download the picture (the default image is used instead of the cell's image)
{
[Self Starticondownload:apprecord forindexpath:indexpath];
}
Cell.imageView.image = [UIImage imagenamed:@ "Placeholder.png"];
}
else//when the Appreacord already has the picture information to display directly
{
Cell.imageView.image = Apprecord.appicon;
}
}
The above is the main code implementation of dynamic loading (which does not include the operation of downloading picture information from the network)
*************************************
Because we create the UITableViewCell is created in a reusable way, so it is equivalent to say that the first screen display of the cell is the basis for the future display of data and pictures, because the later data beyond a flat, we just change the data display, does not create a corresponding one for each cell's data element
UITableViewCell (This is a very wasteful memory), if we don't realize
-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView
And
-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate
Agent, when we roll UITableView when the TableView is in order to load the information resources of the picture, so when we force the table to feel quite the card, (in fact, UITableView really show the cell information)
When we implement the above agent, it can be implemented in the TableView scrolling stop, the load of data information, so that the Tableviewcell during scrolling can be displayed with the default picture information. |
iOS Ableviewcell dynamically loading data, mimicking Himalaya Dynamic Data loading