3

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

  • Were you able to solve this problem? I'm also getting slow load times with a similar approach `UINib(nibName: Self.className, bundle: nil).instantiateWithOwner(nil, options: nil).first as? Self` – Afonso Aug 01 '16 at 13:57

1 Answers1

2

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.

Tim
  • 404
  • 6
  • 16
  • Thank You!!! I had fonts from a previous project selected, which weren't even in this project. Changing all of them to System solved it. I don't think I would have thought of that if it weren't for your post. Thanks again :-) – Elijah Apr 28 '17 at 20:36