@IBDesignableclass ABCMyVIEw: UIVIEw { // (IBOutlets and other code omitted) required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonInit() } overrIDe init(frame: CGRect) { super.init(frame: frame) commonInit() } private func commonInit() { let nib = UINib(nibname: "ABCMyVIEwContents",bundle: NSBundle.mainBundle()) let vIEw = nib.instantiateWithOwner(self,options: nil).first as! UIVIEw addSubvIEw(vIEw) }}
尝试在Interface Builder中查看ABCMyVIEw时,它崩溃了.尝试调试崩溃会导致它在尝试使用所有者实例化nib的行上崩溃.没有错误消息,只是堆栈跟踪最终在汇编代码中(libobjc.A.dylib`objc_exception_throw :).
这是我在异常断点上在控制台中尝试过的一些事情:
(lldb) po nib<UINib: 0x78ef8f20>(lldb) po nib.instantiateWithOwner(self,options: nil)error: Execution was interrupted,reason: breakpoint 1.1.The process has been returned to the state before Expression evaluation.
当我运行应用程序时,一切都运行正常,只有在尝试查看Interface Builder中的UIVIEw失败时才会这样.
如何从IBDesignable加载Nib文件?
解决方法 看起来它正在被使用的NSBundle出现问题.我能够通过将NSBundle.mainBundle()更改为NSBundle(forClass:self.dynamicType)来解决此问题.我从这篇博文中得到了这个想法:Create an IBDesignable UIView subclass with code from an XIB file in Xcode 6.
总结以上是内存溢出为你收集整理的xcode – 尝试实例化笔尖时IBDesignable崩溃全部内容,希望文章能够帮你解决xcode – 尝试实例化笔尖时IBDesignable崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)