0

有許多關於UINavigationController的問題。我修改我的代碼效仿蘋果的例子,但pushViewController方法是行不通的:UINavigationController無法正常工作(pushViewController忽略視圖)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

[window addSubview:navController.view]; 

[window makeKeyAndVisible]; 

LoginController *login = (LoginController*)[self.navController.viewControllers objectAtIndex:0]; 

if([login already_validated] == TRUE) { 
    self.timeline = [[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]]; 

    [navController pushViewController:timeline animated:YES]; 

    [self.timeline release]; 
} 

return YES;  

的觀點是在該行正確裝入:

self.timeline = [[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]]; 

...但

[navController pushViewController:timeline animated:YES]; 

不顯示該視圖。我檢查過並且navController不爲空。

任何想法?

最好!

盧卡斯。


固定!

問題出在MainWindow.xib

不要在窗口類中設置rootViewController

如果您在XIB文件上設置了該屬性,該視圖將位於其他任何位置。

回答

0

您不應該直接發送release到屬性!內存管理是在你的setter方法中完成的!

代替:

[self.someProperty release]; 

寫:

self.someProperty = nil; 

通常你在dealloc方法做到這一點。

在你的情況下,只需刪除行[self.timeline release];或根本不使用屬性。

編輯

添加一個自動釋放:

self.timeline = [[[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]] autorelease]; 
+0

,因爲它是寫現在是混亂的,但如果它是一個保留屬性,實際上他必須在'self.timeline'內部釋放該對象,因爲他之前將其分配在一行中。 – 2011-06-13 16:58:22

+0

謝謝貢薩洛。其實我刪除了財產:) – Lucas 2011-06-13 18:03:55

0

試試這一個..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  


[window addSubview:navController.view]; 


[window makeKeyAndVisible]; 


LoginController *login = (LoginController*)[navController.viewControllers objectAtIndex:0];//here remove self 


if([login already_validated] == TRUE) { 

    self.timeline = [[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:nil];//remove the nsbundle mainbundle 


    [navController pushViewController:self.timeline animated:YES];//here u have to use with self.timeline 

    [self.timeline release]; 

} 

return YES; 
+0

我試圖刪除並添加你提到的東西。沒有運氣:(。 – Lucas 2011-06-13 18:36:24

+0

檢查TimelineViewController筆尖或時間軸筆尖你have.and刪除nsbundle mainbundle爲零 – 2011-06-14 07:35:19