我尝试通过调用instantiateWithOwner从nib加载自定义的UI视图。
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
}
视图加载成功,但加载时间较长(5秒)。 当我跟踪代码时,发现延迟的原因在于此行:
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
我删除了所有自动布局约束,但仍然延迟调用。
UINib(nibName: Self.className, bundle: nil).instantiateWithOwner(nil, options: nil).first as? Self
也遇到了加载缓慢的问题。 - Afonso