IPhone TableImplementationDynamicLoadImageThe tutorial is described in this article, mainly based on code implementation. Let's take a look at the content.
IPhoneWhen loading the list, if you wait for all the data in the list to be fully loaded and the relevant content is displayedImage, Loading time is relatively long, so the effect for the user is very poor, the following is a detailed implementationDynamicLoadImageMethod:
- -(UITableViewCell *) tableView :( UITableView *) tableView
- CellForRowAtIndexPath :( NSIndexPath *) indexPath {
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "tag"];
- If (cell = nil ){
- Cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle
- ReuseIdentifier: @ "tag"] autorelease];
- }
- // Table Design
- NSDictionary * one = [array objectAtIndex: indexPath. row];
- Cell. textLabel. text = [one objectForKey: @ "title"];
- Cell. detailTextLabel. text = [one objectForKey: @ "content"];
- [NSThread detachNewThreadSelector: @ selector (updateImageForCellAtIndexPath :) toTarget: self withObject: indexPath];
- Return cell;
- }
-
- -(Void) updateImageForCellAtIndexPath :( NSIndexPath *) indexPath
- {
- NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
- UIImage * image = [self getImageForCellAtIndexPath: indexPath];
- UITableViewCell * cell = [self. tableView cellForRowAtIndexPath: indexPath];
- [Cell. imageView into mselecw.mainthread: @ selector (setImage :) withObject: image waitUntilDone: NO];
- [Image release];
- [Pool release];
- }
- -(UIImage *) getImageForCellAtIndexPath :( NSIndexPath *) indexPath
- {
- Id path = [[array objectAtIndex: indexPath. row] objectForKey: @ "image"];
- NSURL * url = [NSURL URLWithString: path];
- NSData * data = [NSData dataWithContentsOfURL: url];
- UIImage * image = [[UIImage alloc] initWithData: data cache: NO];
- Return image;
- }
Source code: http://easymorse-iphone.googlecode.com/svn/trunk/WelcomePavilion/
Summary:IPhone TableImplementationDynamicLoadImageI hope this article will help you with the introduction of this tutorial.