Sluggish scrolling when using QuartzCore to round corners in a UIImageView in a UITableViewCell

I use QuartzCoreto add rounded corners to mine UIImageViewin my cellsUITableView

This is the code I'm using:

fooImageView.layer.cornerRadius = 9.0;
fooImageView.layer.masksToBounds = YES;
fooImageView.layer.borderWidth = 1.0;

The problem is when I add this code. The movement of the table cells slows down sharply. I'm just wondering if there are other alternatives to get the user to work much faster and improve performance when scrolling through a table cell using this technique?

I see a lot of apps (most Twitter apps) that don't have a performance hit when using rounded corners for images in their cells. Just wondering how they overcome “slowness”?

Thank you for your help.

+5
source share
5 answers

There are 3 main methods for improving the performance of a UITableView that I use:

  • Always reuse cells, use dequeuereusablecellwithidentifier when creating new cells. This prevents the OS overhead from creating and destroying many objects during fast scrolling.

  • Collapse the cell view hierarchy. Instead of having many views and subtitles, create a custom view and do all of your drawRect. Applications such as using Twitter this approach for super fast cell drawing.

  • , . , , -, , "".

:

cellForRowAtIndexPath ( , ):

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
// Create a new cell if necessary
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIdentifier] autorelease];
}

UITableViews: http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007318-Intro-DontLinkElementID_2

, ,

Dave

+5

, , :

fooImageView.layer.shouldRasterize = YES;

. CALayer UIScrollView a , .

fooImageView.layer.rasterizationScale = [[UIScreen mainScreen] scale];

( ).

+15

. , , .

reuseCellIdentifier, , .

+2

: .

StuDave Magic Bullet, Tweetie UITableView Twitter, . .

, , UITableView () , , . , , Apple. UIViewController, UITableViewController.

+1

In my case, he added endless subpoints, and the table view slowed dramatically, as you said. I added this logic in willDisplayCellto fix the problem:

if cell.contentView.subviews.count < 3 /* elements in cell + subviews */  { 

        cell.contentView.addSubview(subView)
        cell.contentView.sendSubviewToBack(subView)

 }
0
source

All Articles