开发者

NSCache and custom UITableView drawing

I have a UITableView which uses a UIView subclass for its backgroundView and selectedBackgroundView properties. Depending on the position (top/bottom round corners), the selection state and some custom detail accessories the views get redrawn.

This might be an expensive operation so I'm thinking about using NSCache for caching some of the drawn views. I'm currently thinking of different approaches:

  • Cache the view depending on its custom properties (not working if a view is used more than once the same time -> fail)
  • Cache the view depending on its custom properties and use a copy of the view (UIView does not conform to NSCopying protocol -> fail)
  • Cache a UIImage representation of the views and assign them in a UIImageView
  • Don't use NSCache at all or don't use custom drawing at all?
  • ???

So iOS-performance-tuners, which appro开发者_JAVA技巧ach would you prefer?

Thx in advance!


Don't prematurely optimize!

Clipping the views isn't that expensive, I have a few apps in the store that scroll at 60FPS while using custom drawn background with drawRect and a roundRect-Mask.

Creating the selectedBackgroundView is even less problem, since the user actively does a task (tap) and if there's like 50ms delay for generating the view, nobody will notice.

Further, NSCache is thread save, so it's a bit slower and most likely more overhead than you want.

Regarding "copy of the view" I don't see any reason why you would want that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜