Tricks For Improving Iphone Uitableview Scrolling Performance

Tricks for improving iPhone UITableView scrolling performance?

  1. Cache the height of the rows (the table view can request this frequently)
  2. Create a least-recently-used cache for the images used in the table (and invalidate all the inactive entries when you receive a memory warning)
  3. Draw everything in the UITableViewCell's drawRect: if possible avoid subviews at all costs (or if you require the standard accessibility functionality, the content view's drawRect:)
  4. Make your UITableViewCell's layer opaque (same goes for the content view if you have one)
  5. Use the reusableCellIdentifier functionality as recommended by the UITableView examples/documentation
  6. Avoid gradients/complicated graphical effects that aren't pre-baked into UIImages

How can I speed up a UITableView?

Even if your cell is actually that simple (background image and label) there are some things to consider

Image caching
This is the obvious thing - if you are using the same image everywhere, load it once into the UIImage and reuse it. Even if the system will cache it on its own, directly using the already loaded one should never hurt.

Fast calculation
Another rather obvious thing - make calculating height and content as fast as possible. Don't do synchronous fetches (network calls, disk reads etc.).

Alpha channel in image
What's expensive when drawing is transparency. As your cell background has nothing behind it, make sure that you save your image without alpha channel. This saves a lot of processing.

Transparent label
The same holds true for the label on top of your background view, unfortunately making it opaque might ruin the looks of your cell - but it depends on the image.

Custom cell
In general, subclassing UITableViewCell and implementing drawRect: yourself is faster than building the subview hierarchy. You might make your image a class variable that all instances use. In drawRect: you'd draw the image and the text on top of it.

Check compositing
The simulator has a tool to highlight the parts that are render-expensive because of transparency (green is ok, red is alpha-blending). It can be found in the debug menu: "Color Blended Layers"

How to improve scroll performance when downloading image thumbnail in tableview

  1. For your issue where the previous image is showing when the cell is reused, you should override func prepareForReuse() in PhotoTableViewCell and set photoImageView.image = nil.
  2. For your performance issue, it looks like you're making the API request off the main thread, so that's a good start. How large are the images you're requesting? I'm wondering if the data is so large that it's taking a lot of time to convert it to an image and then set the image on the image view

How To Make Scrolling UITableView Smoother?

This is how you load custom cells

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndetifier];
}

NSDictionary *article = [entriesArray objectAtIndex:[indexPath row]];
NSString *title = [article objectForKey:@"title"];
NSString *date = [article objectForKey:@"publishedDate"];
NSString *dateEdited = [date substringToIndex:16];

cell.nameLabel.text = title;
cell.dateLabel.text = dateEdited;

NSURL *myURL=[NSURL URLWithString:[self.picturesArray objectAtIndex:indexPath.row]];
NSData *myData1 = [[NSData alloc] initWithContentsOfURL:myURL] autorelease];
UIImage *myImage = [[UIImage alloc] initWithData:myData1] autorelease];

cell.imageView.image = myImage;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;

return [cell autorelease];
}

UITableview scroll freezes and becomes slow with usage

Okay it was from the gesture recognizer as i said. I just replaced it with a button with the same size of the pic. It's on the pic with alpha = 0. Whenever i need the tap recognition, i just activate the alpha of the button which already has an IBAction. Hope this helps...



Related Topics



Leave a reply



Submit