2

I have used custom cell class for my uitableview and used in cellForRowAtIndexPath method.

In that method cellIdentifier is already been defined and even cell property is used as dequeueReusable.

But while scrolling my tableview each time my custom cell objects gets created and its methods get called. Because of that on device, scrolling gets jerky effects.

I have also checked if(cell==nil) and inside that i m assigning my image and labels property for that custom cell. But each and every time, this condition gets true and program pointer goes inside that condition.

Please guide me on this.

If possible please provide some example code.

Thanks in advance

Mrunal.

2
  • 1
    You'll need to post your cellForRowAtIndexPath method for anyone to help you.
    – jrturton
    Aug 27, 2011 at 7:43
  • 3
    No, no, no, mrunal, you provide your code.
    – BoltClock
    Aug 27, 2011 at 7:57

3 Answers 3

15

I have pretty complex UITableViewCell. For me the trick was to set the shouldRasterize of the cell layer's to YES. But it introduced blurry text. To avoid that I set the scale - [self.layer setRasterizationScale:[[UIScreen mainScreen] scale]].

0
13

As many others have pointed out, we can't really help you unless you post your code (your CellForRowAtIndexPath should be enough).

Generally speaking there are many ways of improving scrolling performance on UITableViews and the top ones I use are (and have used in other Stack Overflow answers):

  1. Always reuse cells, use the dequeuereusablecellwithidentifier when creating new cells. This prevents the overhead of the OS creating and destroying lots of objects when scrolling fast.

  2. Collapse the view hierarchy of the cell. Instead of having lots of views and subviews, create a custom view and do all your cell drawing in the drawRect. Apps like Twitter use this approach for super fast cell drawing.

  3. Ensure your images are opaque. You can do this by ensuring all image assets don't have alpha channels baked into them and by setting the layer's opaque property to YES.

  4. If you are setting any properties of the cell image's layer property (like shadow or rounded rectangles) this can affect scrolling performance. Setting the layer's shouldRasterize to YES will help, but you should really think hard about doing any intensive drawing operations within cells.

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

2
  • For me setting opaque property of the layer of cell to YES and shouldRasterize to YES eliminated all the jitter that I was getting. BTW, my cell is quite complicated. Sep 6, 2013 at 15:12
  • 2
    Your 4th point worked like Rocket ! Awsm . . . (y) but need to add - [self.layer setRasterizationScale:[[UIScreen mainScreen] scale]]. after that. Feb 3, 2016 at 7:22
1

This is happening because of ImageView. Create your labels and imageViews inside if(cell == nil) in CellAtIndexPathMehtod of UITableView and assign its value outside this if.

And If your images are loading from server then use Asynchrnous image loading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.