无法从nib实例化UIView。 “警告:无法加载任何Objective-C类信息” [英] Cannot instantiate UIView from nib. "warning: could not load any Objective-C class information"
问题描述
我得到无法加载任何Objective-C类信息。这将显着降低可用类型信息的质量。初始化此类实例时在控制台中发出警告:
I get "could not load any Objective-C class information. This will significantly reduce the quality of type information available." warning in the console while initializing an instance of this class:
@IBDesignable
class SystemMessage: UIView{
@IBOutlet weak var lbl_message: UILabel!
var view: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup(){
view = loadViewFromNib()
view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
addSubview(view)
}
func loadViewFromNib() -> UIView{
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "SystemMessage", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
}
执行停止在行让view = nib.instantiateWithOwner ...
withThread 1:EXC_BAD_ACCESS(code = 2 ...)
Execution stops on line let view = nib.instantiateWithOwner...
with "Thread 1: EXC_BAD_ACCESS(code=2...)"
这背后可能的原因是什么?
What could be the possible reason behind this?
推荐答案
找到了解。这一切都是为了理解xib是如何工作的。
Found the solution. It all comes to understanding of how xibs work.
我所做的是我为视图和文件所有者设置了类,并连接了View中的所有出口而不是文件的所有者。
What I did was that I set class for both view and File's Owner and connected all the outlets from the View rather than from the File's owner.
这篇关于无法从nib实例化UIView。 “警告:无法加载任何Objective-C类信息”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!