Hossam Fathy
Hossam Fathy

Reputation: 79

slow loading of nib in swift2 by instantiateWithOwner

i try to load a custom uiview from a nib by calling instantiateWithOwner

func loadViewFromNib() -> UIView {
    let bundle = NSBundle(forClass: self.dynamicType)
    let nib = UINib(nibName: "myCustomView", bundle: bundle)
     let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
    return view
}

the view is loading successfully but it long time to load (5 seconds). when i traced the code i found that the reason of delaying in this line :

let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

i removed all autolayout constraints but it still delay in calling

Upvotes: 3

Views: 515

Answers (1)

Tim
Tim

Reputation: 404

I have the same problem, and I found that it's due to the font from the UILabel or other views need font. Change the font to "System Font" solved the problem.

If you remove all subviews from nib you will notice that the loading time is very fast. Then add subview back one by one to check which view slow the time.

Upvotes: 2

Related Questions