IOS/Swift: optimal way to generate dozens of views from a NIB

84 Views Asked by At

Complete IOS newbie here...

I'm writing a calendar app and trying to recreate this display:

enter image description here

So I created a custom view, subclassing UIView. I pass this view an array of Appointment objects (my own custom objects), and for each one, I create a view and call addSubView.

First test went great.

But since I want my app to display a little bit more info for each appointment, I decided to create another custom UI class with an associated nib.

Now I have to deserialize the nib file for each appointment I want to show, and this takes 100 times longer than the previous code:

let v = NSBundle.mainBundle().loadNibNamed("SingleAppointmentView", owner: nil, options: nil)[0] as! SingleAppointmentView;

Is there a better way to do this? Can I deserialize the nib once and then duplicate it? or should I just create my SingleAppointmentView in code, and let go of the convenience of a nib file?

0

There are 0 best solutions below