无法在捆绑包中加载 NIB
Posted
技术标签:
【中文标题】无法在捆绑包中加载 NIB【英文标题】:Could not load NIB in bundle 【发布时间】:2016-06-10 14:27:18 【问题描述】:2016-06-10 16:16:15.340 SwipePageTest[4625:434547] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Alexk/Library/Developer/CoreSimulator/Devices/1A09A104-D0BF-44EA-8FAD-B90A3599FF8C/data/Containers/Bundle/Application/3213D8DB-6294-43C0-A4F6-AF075812EE3D/SwipePageTest.app> (loaded)' with name 'ViewControler0''
*** First throw call stack:
(
0 CoreFoundation 0x00000001087cfd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a573deb objc_exception_throw + 48
2 CoreFoundation 0x00000001087cfcbd +[NSException raise:format:] + 205
3 UIKit 0x00000001093bfc89 -[UINib instantiateWithOwner:options:] + 499
4 UIKit 0x00000001091918d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
5 UIKit 0x0000000109192202 -[UIViewController loadView] + 178
6 UIKit 0x0000000109192560 -[UIViewController loadViewIfRequired] + 138
7 UIKit 0x0000000109192cd3 -[UIViewController view] + 27
8 SwipePageTest 0x00000001085e4cf4 _TFC13SwipePageTest14ViewController11viewDidLoadfT_T_ + 500
9 SwipePageTest 0x00000001085e6422 _TToFC13SwipePageTest14ViewController11viewDidLoadfT_T_ + 34
10 UIKit 0x0000000109192984 -[UIViewController loadViewIfRequired] + 1198
11 UIKit 0x00000001091d6fae -[UINavigationController _layoutViewController:] + 54
12 UIKit 0x00000001091d7882 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
13 UIKit 0x00000001091d79f4 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
14 UIKit 0x00000001091d8c4d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
15 UIKit 0x00000001091d9d0b -[UINavigationController __viewWillLayoutSubviews] + 57
16 UIKit 0x0000000109388503 -[UILayoutContainerView layoutSubviews] + 248
17 UIKit 0x00000001090b2980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
18 QuartzCore 0x000000010da7dc00 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x000000010da7208e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x000000010da71f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x000000010da663c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
22 QuartzCore 0x000000010da94086 _ZN2CA11Transaction6commitEv + 486
23 QuartzCore 0x000000010da947f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
24 CoreFoundation 0x00000001086f4c37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x00000001086f4ba7 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x00000001086ea11c CFRunLoopRunSpecific + 524
27 UIKit 0x0000000108ff2f21 -[UIApplication _run] + 402
28 UIKit 0x0000000108ff7f09 UIApplicationMain + 171
29 SwipePageTest 0x00000001085e7252 main + 114
30 libdyld.dylib 0x000000010b03792d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
代码:
let vc0 = ViewController0(nibName: "ViewControler0", bundle: nil)
self.addChildViewController(vc0)
self.scrollVIew.addSubview(vc0.view)
vc0.didMoveToParentViewController(self)
let vc1 = ViewController1(nibName: "ViewControler1", bundle: nil)
var frame1 = vc1.view.frame
frame1.origin.x = self.view.frame.size.width
vc1.view.frame = frame1
self.addChildViewController(vc1)
self.scrollVIew.addSubview(vc1.view)
vc1.didMoveToParentViewController(self)
let vc2 = ViewController2(nibName: "ViewControler2", bundle: nil)
var frame2 = vc2.view.frame
frame2.origin.x = self.view.frame.size.width * 2
vc2.view.frame = frame2
self.addChildViewController(vc2)
self.scrollVIew.addSubview(vc2.view)
vc2.didMoveToParentViewController(self)
let vc3 = ViewController3(nibName: "ViewControler3", bundle: nil)
var frame3 = vc3.view.frame
frame3.origin.x = self.view.frame.size.width * 3
vc3.view.frame = frame3
self.addChildViewController(vc3)
self.scrollVIew.addSubview(vc3.view)
vc1.didMoveToParentViewController(self)
【问题讨论】:
【参考方案1】:在文件检查器中访问.xib文件的属性,选择框上的“目标成员”属性,然后你的xib文件与你的目标链接
【讨论】:
以上是关于无法在捆绑包中加载 NIB的主要内容,如果未能解决你的问题,请参考以下文章