UIView or UIImage in a UITableView, what's better for performance
I have a UITableView where we want to just put a colored square. Depending on the data in the UITableViewCell, the UIView changes its background color. That's the way it currently is. To me, it seems better to just have a UIImageView and have a .png image for the different color squares, and load the correct one per cell depending on the data in the UITableViewCell. I'm not sure which method is better, or if there is an even better method I do not know of. Any thoughts? 开发者_JS百科 Thanks.
Having worked with images contained in table cells, I have to believe that simply using a UIView and setting it's background color to whatever you need is going to be far faster.
Even with local images (those in your app bundle), think of all the extra work you'd be incurring to create a UIImage and then set the UIImageView's image property?
In my case, on two different projects, I had to load images off the 'net into table cells. Quite slow, so we did it in the background, which had it's own challenges and special conditions to deal with. This would be overkill for what you describe though.
I'd go with UIView's and background colors. Of course, you could try it yourself both ways and see how it works for you. :-) Remember to test on a real device, because it's easy to be lulled into a sense of "everything is GREAT!" when you watch your app scream on the simulator! :-)
I think it it better to fill background with some color rather then load images from file. It will be much more quickly, as you don't need to access file system.
Definitely just use the view’s background color. An opaque view filled with a solid color is one of the fastest things you can draw; a PNG will be notably slower, will consume more memory, and will needlessly bloat the size of your app bundle.
精彩评论