我正在尝试使用 Storyboard 将导航 Controller 嵌入到容器 View 中。我将我的容器 View 添加到我的场景,删除它自动生成的 View Controller ,然后按住控制键从容器 View 拖动到我的导航 Controller ,创建一个 segue。
当我在模拟器中运行应用程序并转换到包含容器 View 的场景时,我得到了这个异常:
2018-04-28 15:22:40.278627-0400 Woofr[8977:18656423] *** 由于未捕获的异常 'NSUnknownKeyException' 而终止应用程序,原因:'[setValue:forUndefinedKey:]: 此类不是键值关键 containerView 的编码兼容。'
如果我将它作为测试运行,只使用原来自动生成的 View Controller ,它就可以工作。如果我在不删除自动生成的 View Controller 的情况下从 Container View 按住 control 并拖动到 Navigation Controller,则 Storyboard 中的 segue 会被替换,但我在运行该应用程序时会遇到相同的异常。
ETA 完整堆栈跟踪:
2018-04-28 15:44:22.748243-0400 Woofr[15437:18687945] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIStoryboardShowSegueTemplate 0x6040004756c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key containerView.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001078521e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000010699a031 objc_exception_throw + 48
2 CoreFoundation 0x00000001078520b9 -[NSException raise] + 9
3 Foundation 0x00000001063bbb47 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x0000000108cc2d56 -[UIRuntimeOutletConnection connect] + 109
5 CoreFoundation 0x00000001077f4e8d -[NSArray makeObjectsPerformSelector:] + 317
6 UIKit 0x0000000108cc1700 -[UINib instantiateWithOwner:options:] + 1856
7 UIKit 0x00000001089dc137 -[UIViewController _loadViewFromNibNamed:bundle:] + 383
8 UIKit 0x00000001089dca64 -[UIViewController loadView] + 177
9 UIKit 0x00000001089dcd81 -[UIViewController loadViewIfRequired] + 175
10 UIKit 0x00000001089dd5d4 -[UIViewController view] + 27
11 UIKit 0x0000000108a0ec6e -[UINavigationController _startCustomTransition:] + 945
12 UIKit 0x0000000108a255e2 -[UINavigationController _startDeferredTransitionIfNeeded:] + 714
13 UIKit 0x0000000108a268cc -[UINavigationController __viewWillLayoutSubviews] + 150
14 UIKit 0x0000000108c7ebd7 -[UILayoutContainerView layoutSubviews] + 231
15 UIKit 0x0000000108908808 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
16 QuartzCore 0x00000001045d161a -[CALayer layoutSublayers] + 177
17 QuartzCore 0x00000001045d582b _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
18 QuartzCore 0x000000010455c29f _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343
19 QuartzCore 0x0000000104589940 _ZN2CA11Transaction6commitEv + 568
20 UIKit 0x000000010883334f _UIApplicationFlushRunLoopCATransactionIfTooLate + 167
21 UIKit 0x0000000109198532 __handleEventQueueInternal + 6875
22 CoreFoundation 0x00000001077f4bb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
23 CoreFoundation 0x00000001077d94af __CFRunLoopDoSources0 + 271
24 CoreFoundation 0x00000001077d8a6f __CFRunLoopRun + 1263
25 CoreFoundation 0x00000001077d830b CFRunLoopRunSpecific + 635
26 GraphicsServices 0x000000010cb86a73 GSEventRunModal + 62
27 UIKit 0x00000001088390b7 UIApplicationMain + 159
28 Woofr 0x0000000100d34427 main + 55
29 libdyld.dylib 0x000000010b050955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
ETA 设置场景截图:
最佳答案
在ViewController
包含 containerView
的类, 请务必添加 IBOutlet
为之
@IBOutlet var containerView: UIView!
当您拖动 ContainerView
进入一个 View 并给它约束,它创建一个 ViewController
从那开始ContainerView
.
嵌入此目的地 ViewController
在NavigationController
来自
编辑器 -> 嵌入 -> 导航 Controller
关于ios - 在容器 View 中嵌入 NavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080320/