从 Xib 加载 UIVied 时,loadNibNamed() 崩溃 [英] When loading UIVied from Xib, loadNibNamed() crashes

查看:35
本文介绍了从 Xib 加载 UIVied 时,loadNibNamed() 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用代码从笔尖加载一个包含 UITableView 的视图:

I am trying to load a View including a UITableView from a nib by using code:

class HintTable:UIView, UITableViewDataSource, UITableViewDelegate{
var searchResults = Array<String>()
let delegate:MovableAnnotationDelegate
@IBOutlet var myTableView:UITableView!

init(frame: CGRect, delegate:MovableAnnotationDelegate) {
    self.delegate=delegate
    super.init(frame: frame)
    loadViewFromNib ()
}

required init?(coder aDecoder: NSCoder) {
    self.delegate=InArrivoHDViewController.sharedDetailController()
    super.init(coder: aDecoder)
    loadViewFromNib ()
}

func loadViewFromNib() {
    NSBundle.mainBundle().loadNibNamed("HintTableView", owner: self, options: nil)
    self.myTableView.backgroundColor=UIColor(red:0.2890625, green:0.75390625, blue:0.3046875, alpha:0.5)
    self.backgroundColor=UIColor(red:0.2890625, green:0.75390625, blue:0.3046875, alpha:0.5)
    print("myTableView %@", self.myTableView);
    self.myTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

}
}

然而它在没有任何提示的情况下崩溃了:

Yet it crashes without any hint whatsoever on command:

NSBundle.mainBundle().loadNibNamed("HintTableView", owner: self, options: nil)

在 Xib 中,我将类设置为文件的所有者,而不是在身份检查器中获取它.我也不太清楚如何访问 tableView,因为 IBOutlet 似乎没有连接.

In the Xib I set the class as File's owner instead of getting it in the identity inspector. I am also quite unclear about how to access the tableView, as the IBOutlet seems unwired.

这是一个崩溃日志:

上次异常回溯:0 CoreFoundation
0x182b3cf48 异常预处理+ 124 1 libobjc.A.dylib
0x197fe7f80 objc_exception_throw + 56 2 CoreFoundation
0x182b3cc08 -[NSException raise] + 12 3 Foundation
0x1839b8014 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 268 4
UIKit 0x1883e3a4c -[UIView(CALayerDelegate)setValue:forKey:] + 184 5 UIKit 0x188596794-[UIRuntimeOutletConnection 连接] + 124 6 CoreFoundation 0x182a669cc -[NSArray makeObjectsPerformSelector:] + 232 7 UIKit
0x18859517c -[UINib instantiateWithOwner:options:] + 1748 8 UIKit
0x188597408 -[NSBundle(UINSBundleAdditions)loadNibNamed:owner:options:] + 224 9 inArrivoHD
0x10023218c 0x100074000 + 1827212 10 inArrivoHD
0x100231bf8 0x100074000 + 1825784 11 inArrivoHD
0x100231d2c 0x100074000 + 1826092 12 inArrivoHD
0x10024ec34 0x100074000 + 1944628 13 inArrivoHD
0x100250678 0x100074000 + 1951352 14 UIKit
0x1880d0098 -[UIViewController loadViewIfRequired] + 996 15 UIKit
0x18818f580 -[UINavigationController _layoutViewController:] + 72 16UIKit 0x18818f458 -[UINavigationController_updateScrollViewFromViewController:toViewController:] + 416 17 UIKit 0x18818e6a0 -[UINavigationController_startTransition:fromViewController:toViewController:] + 144 18 UIKit 0x18818e244 -[UINavigationController_startDeferredTransitionIfNeeded:] + 868 19 UIKit 0x18818de6c -[UINavigationController __viewWillLayoutSubviews] + 6020 UIKit 0x18818ddd4 -[UILayoutContainerViewlayoutSubviews] + 208 21 UIKit 0x1880cb7ac-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 644 22 QuartzCore 0x1878cab58 -[CALayer layoutSublayers]+ 148 23 QuartzCore 0x1878c5764 CA::Layer::layout_if_needed(CA::Transaction*) + 292 24 QuartzCore
0x1878c5624 CA::Layer::layout_and_display_if_needed(CA::Transaction*)+ 32 25 QuartzCore 0x1878c4cc0 CA::Context::commit_transaction(CA::Transaction*) + 252 26 QuartzCore0x1878c4a08 CA::Transaction::commit() + 512 27 QuartzCore
0x1878be0f8 CA::Transaction::observer_callback(__CFRunLoopObserver*,unsigned long, void*) + 80 28 CoreFoundation
0x182af3bd0__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 32 29 CoreFoundation 0x182af1974 __CFRunLoopDoObservers +372 30 核心基金会 0x182a20cc0CFRunLoopRunSpecific + 416 31 UIKit
0x18813e1c8 -[UIApplication _run] + 460 32 UIKit
0x188138ffc UIApplicationMain + 204 33 inArrivoHD
0x1002cc3c0 0x100074000 + 2458560 34 libdyld.dylib
0x19882a8b8 开始 + 4

Last Exception Backtrace: 0 CoreFoundation
0x182b3cf48 exceptionPreprocess + 124 1 libobjc.A.dylib
0x197fe7f80 objc_exception_throw + 56 2 CoreFoundation
0x182b3cc08 -[NSException raise] + 12 3 Foundation
0x1839b8014 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 268 4
UIKit 0x1883e3a4c -[UIView(CALayerDelegate) setValue:forKey:] + 184 5 UIKit 0x188596794 -[UIRuntimeOutletConnection connect] + 124 6 CoreFoundation 0x182a669cc -[NSArray makeObjectsPerformSelector:] + 232 7 UIKit
0x18859517c -[UINib instantiateWithOwner:options:] + 1748 8 UIKit
0x188597408 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 224 9 inArrivoHD
0x10023218c 0x100074000 + 1827212 10 inArrivoHD
0x100231bf8 0x100074000 + 1825784 11 inArrivoHD
0x100231d2c 0x100074000 + 1826092 12 inArrivoHD
0x10024ec34 0x100074000 + 1944628 13 inArrivoHD
0x100250678 0x100074000 + 1951352 14 UIKit
0x1880d0098 -[UIViewController loadViewIfRequired] + 996 15 UIKit
0x18818f580 -[UINavigationController _layoutViewController:] + 72 16 UIKit 0x18818f458 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 416 17 UIKit 0x18818e6a0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 144 18 UIKit 0x18818e244 -[UINavigationController _startDeferredTransitionIfNeeded:] + 868 19 UIKit 0x18818de6c -[UINavigationController __viewWillLayoutSubviews] + 60 20 UIKit 0x18818ddd4 -[UILayoutContainerView layoutSubviews] + 208 21 UIKit 0x1880cb7ac -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 644 22 QuartzCore 0x1878cab58 -[CALayer layoutSublayers] + 148 23 QuartzCore 0x1878c5764 CA::Layer::layout_if_needed(CA::Transaction*) + 292 24 QuartzCore
0x1878c5624 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32 25 QuartzCore 0x1878c4cc0 CA::Context::commit_transaction(CA::Transaction*) + 252 26 QuartzCore 0x1878c4a08 CA::Transaction::commit() + 512 27 QuartzCore
0x1878be0f8 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80 28 CoreFoundation
0x182af3bd0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 32 29 CoreFoundation 0x182af1974 __CFRunLoopDoObservers + 372 30 CoreFoundation 0x182a20cc0 CFRunLoopRunSpecific + 416 31 UIKit
0x18813e1c8 -[UIApplication _run] + 460 32 UIKit
0x188138ffc UIApplicationMain + 204 33 inArrivoHD
0x1002cc3c0 0x100074000 + 2458560 34 libdyld.dylib
0x19882a8b8 start + 4

推荐答案

我最终在 Storyboard 的主 ViewController 中插入了视图,并将委托和源适当地分配给了视图.

I ended up inserting the view in the main ViewController of the Storyboard and assigning the delegate and source appropriately to the View.

这篇关于从 Xib 加载 UIVied 时,loadNibNamed() 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆