【发布时间】:2013-01-05 08:54:32
【问题描述】:
我正在尝试将视图控制器容器 library 添加到 remail 电子邮件客户端。这个想法是视图控制器容器presents its child view controllers in two layers. It provides functionality for sliding the top view to reveal the views underneath it.
在库描述中,这是将子 controllerView 附加到其父级的建议方法:
if (![self.slidingViewController.underLeftViewController
isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController =
[self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
其中 slidingViewController 是 the top-level instance of the view controller container. With this instance, you can set the view controllers underneath the top view and add panning.
我使用的是 xib 文件,而不是楼层板。所以我的代码看起来像这样:
if (![self.slidingViewController.underLeftViewController
isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController =
[[MenuViewController alloc] initWithNibName:@"Menu" bundle:nil];
}
但使用该代码.. 我收到此错误:-[__NSArrayM insertObject:atIndex:]: object cannot be nil
可以追踪到slidingViewController 执行以下操作:[self.view insertSubview:_underTopViewController.view atIndex:0];
查看文档。我发现instantiateViewControllerWithIdentifier 和initWithNibName 之间存在差异:前者始终返回一个对象。而后者仅加载the first time the view controller’s view is accessed。
问题:如何让 initWithNibName 返回一个加载的 viewcontroller 对象,无论该视图是否已被访问......类似于 instantiateViewControllerWithIdentifier?
【问题讨论】:
标签: ios xcode storyboard nib uistoryboard