2012-04-10 80 views
0

我有以下代碼:問題與推到導航欄

- (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]; 

但是現在,當我努力表現自我。 bookNavigationController作爲模式視圖控制器,正如myBookVC不存在。爲什麼是這樣?它只是通過導航欄顯示一個空的視圖。

回答

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]; 
+0

做到了這一點,並沒有幫助 – xonegirlz 2012-04-10 17:15:14