我正在构建一个自定义容器 ViewController 来容纳一个笔尖的几个实例。这个 nib 包含一个 ViewController 子类为 DemoViewController
在容器的 viewWillAppear 期间,我执行以下操作:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"Container will appear");
if (_selectedViewController.parentViewController == self)
{
// nowthing to do
return;
}
DemoViewController *vc = [[DemoViewController alloc] initWithNibName:@"Gauge" bundle:nil];
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"Gauge" owner:self options:nil];
// assuming the view is the only top-level object in the nib file (besides File's Owner and First Responder)
UIView *nibView = [nibObjects objectAtIndex:0];
// add as child VC
[self addChildViewController:vc];
[view1 addSubview:nibView];
// notify it that move is done
[vc didMoveToParentViewController:self];
}
在运行时,我收到以下异常:
2012-07-02 21:59:22.734 ContainerViewController[21747:f803] 加载容器视图 2012-07-02 21:59:22.737 ContainerViewController[21747:f803] 容器将出现 2012-07-02 21:59:22.740 ContainerViewController [21747:f803] 仪表视图已加载 2012-07-02 21:59:22.742 ContainerViewController[21747:f803] 仪表将移至父控制器 2012-07-02 21:59:22.743 ContainerViewController[21747:f803]-[DemoViewController superview]:无法识别的选择器发送到实例 0x6a7daa0 2012-07-02 21:59:22.745 ContainerViewController[21747:f803] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[DemoViewController superview]:无法识别的选择器发送到实例 0x6a7daa0” *** 首先抛出调用堆栈: (0x13c9022 0x155acd6 0x13cacbd 0x132fed0 0x132fcb2 0x4fe4f 0x4a14b 0x2d2c 0xdc38f 0xdc5eb 0xdd4ed 0x4aa0c 0x4ff92 0x4a14b 0x39550 0x39670 0x39836 0x4072a 0x11596 0x12274 0x21183 0x21c38 0x15634 0x12b3ef5 0x139d195 0x1301ff2 0x13008da 0x12ffd84 0x12ffc9b 0x11c65 0x13626 0x276d 0x26d5) 终止称为抛出异常(lldb)
有人知道这里发生了什么吗?不幸的是,关于容器视图控制器的文档很少,所以我很难过。