2010-11-09 47 views
0

我有一個有兩個項目的tabbar應用程序。這兩個不同的標籤欄項目包含2個不同的導航控制器。 第一個導航控制器工作正常,但是當我想將視圖推到第二個導航時,它會生成 「應用程序嘗試將nil視圖控制器推到目標上」。將視圖推到第二個導航控制器

這裏是我把視圖推向第二個導航控制器的代碼。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

TabNavAppDelegate *appDelegate = (TabNavAppDelegate *)[[UIApplication sharedApplication] delegate]; 
JJ_MapAnnotation *anno = (JJ_MapAnnotation *) [depotsArray objectAtIndex:indexPath.row]; 
if(self.secondViewController ==nil) 
{ 
    SecondViewController *secView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
    self.secondViewController == secView; 
    [self.secondViewController.map addAnnotation:anno]; 
    [secView release]; 
} 


secondViewController.title = [NSString stringWithFormat:@"%@", [anno title]]; 

[appDelegate.navController pushViewController:secondViewController animated:YES]; 

回答

0

我敢打賭,在該行:

if(self.secondViewController ==nil) 

self.secondViewControllernil也不是一個有效的對象。可能有一些垃圾在那裏。 當你做這樣的動態分配時,確保你的對象在釋放後變爲零。否則,你可以有這樣的情況。 我希望它能幫助

UPDATE:

==操作不正確,在這裏;)

self.secondViewController == secView; //WRONG 
self.secondViewController = secView; //OK 
+0

嗨感謝您的快速回復,但即使我刪除代碼,它仍然會產生同樣的錯誤 – EnginBodur 2010-11-09 15:43:44

+0

大聲笑。愚蠢的錯誤;)檢查我更新的答案。 – nacho4d 2010-11-09 15:52:18

+0

謝謝夥伴,你讓我的日子=))讚賞!!! – EnginBodur 2010-11-09 15:57:52

相關問題