我正在尝试将视图控制器容器库添加到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"];
}
滑动视图控制器在哪里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?