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