Reputation: 6643
I'm trying to find out which approach is better to create the same controls in a view. Let's say that I have a UIview which I want to display 100 custom controls in it. each custom control contains 2 uiImageView and 3 uiLabel. Now there are 2 approaches to do that:
Create a nib with this controls, its file owner is UIView and load it 100 times with InitWithFrame. So I have 100 uiViews, with 5 controls each = 600 uicontrols
create the controls programmatically, all on the same uiview. So I have 5 * 100 = 500 uicontrols.
So it seems that approach 2 is better in memory consumption, but is it really? and what about loading time of each approach? which is better?
Thank you
Upvotes: 0
Views: 125
Reputation: 6643
I found out that a third approach is the best: Use UITableView to create the view. That way you'll use the reuse abilities of the uitable. The 2 approaches suggested in the question will create a memory warning at some point if you don't reuse the controls (as uitable reuse its rows).
Upvotes: 1
Reputation: 1689
The second approach to create the controls is faster. Both solutions have to create controls, but the first approach has the overhead of parsing the NIB file. The question is: how much faster is the second approach. And: is the first approach so slow that it will impact your particular application?
Here is a good code sample for timing short-duration events: http://zpasternack.blogspot.com/2012/07/high-resolution-timing-in-cocoa.html
Upvotes: 1