我有以下代码:
- (void)setupBook
{
if (self.bookNavigationController) {
BookViewController *bookVC = [[BookViewController alloc] initWithTemplate:x];
self.myBookVC = bookVC;
[bookVC release];
myBookVC.pageTitle = @"My Book";
UINavigationController *nController = [[UINavigationController alloc] initWithRootViewController:myBookVC];
self.bookNavigationController = nController;
[nController release];
}
}
然后在我的代码的其他部分:
[self.someOtherNavigationController pushViewController:self.bookVC];
然而现在当我尝试将self.bookNavigationController呈现为模态视图控制器时,它就像myBookVC不存在一样。为什么是这样?它只显示一个带导航栏的空视图。
答案 0 :(得分:0)
何时首先创建视图控制器,您将其分配给属性,但是当指定为导航控制器的rootViewController时,您将引用一个ivar。在分配rootViewController时使用该属性。
BookViewController *bookVC = [[BookViewController alloc] initWithTemplate:x];
bookVC.pageTitle = @"My Book";
self.myBookVC = bookVC;
[bookVC release];
UINavigationController *nController = [[UINavigationController alloc] initWithRootViewController:self.myBookVC];
self.bookNavigationController = nController;
[nController release];