开发者

UITableview gets jerky while scrolling because of custom cell creation?

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 conditio开发者_开发百科n.

Please guide me on this.

If possible please provide some example code.

Thanks in advance

Mrunal.


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]].


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜