2011-08-31 99 views
1

我是iPhone SDK開發新手,我不是英國人,所以我對我的關卡表示歉意。exc_bad_access dismissModalViewControllerAnimated

這裏是我的問題: 我有一個tabBarcontroller,有3項,每個人都有一個navBarcontroller

[self.loginViewController release]; 
[self setLoginViewController:[[LoginViewController alloc] init]]; 
[[self loginViewController] setDelegate:self]; 
[[self loginViewController] isLoggued]; 

self.tabBarController = [[UITabBarController alloc] init]; 

_FirstViewController = [[[FirstViewController alloc] init] autorelease]; 
_FirstViewController.title = @"title 1"; 

UINavigationController* navController1 = [[[UINavigationController alloc] 
              initWithRootViewController:_FirstViewController] autorelease]; 

_SecondViewController = [[[SecondViewController alloc] init] autorelease]; 
_SecondViewController.title = @"title 2"; 

UINavigationController* navController2 = [[[UINavigationController alloc] 
              initWithRootViewController:_SecondViewController] autorelease]; 

_ThirdViewController = [[[_ThirdViewController alloc] init] autorelease]; 
_ThirdViewController.title = @"title 3"; 

UINavigationController* navController3 = [[[UINavigationController alloc] 
              initWithRootViewController:_ThirdViewController] autorelease]; 

self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, navController2, navController3, nil]; 
[self.window addSubview:self.tabBarController.view]; 
// adds the tab bar's view property to the window 
[self.window makeKeyAndVisible]; 

[self.tabBarController release]; 

if ([self respondsToSelector:@selector(loginViewControllerLogout:)]) { 
    [self performSelector:@selector(loginViewControllerLogout:) withObject:[self loginViewController]]; 
} 

return YES; 

這兒,這是選擇

-(void)loginViewControllerLogout:(LoginViewController *)loginViewController { 

if (![self.loginViewController logguedIn]) 
    [self.tabBarController presentModalViewController:self.loginViewController animated:YES]; 
} 

,當我loggued,我致電:

-(void)loginViewControllerDidFinish:(LoginViewController *)loginViewController { 
    [self.loginViewController dismissModalViewControllerAnimated:YES]; 
} 

這段代碼在應用程序啓動時爲冷杉時間。 LoginViewController顯示>登錄成功> LoginViewcontroller關閉> FirstViewController顯示。 但是如果我去第三個控制器,點擊註銷: 選擇器LoginViewControllerLogout調用> LoginViewController顯示>登錄成功>在dismissModal中崩潰。

沒有錯誤堆棧,只是exc_bad_access錯誤。 loginViewController有多個保留。

在此先感謝

編輯:所有的功能都在AppDelegate中

回答

0

代替

[self.tabBarController presentModalViewController:self.loginViewController animated:YES]; 

試試這個

[self presentModalViewController:self.loginViewController animated:YES]; 

這應該工作,你在呈現模式你的窗口,而不是tabbar ..

[self presentModalViewController:loginViewController animated:YES]; 
+0

就像我對比爾說,我不能這樣做怎麼把自我是我的AppDelegate *,所以不存在「self.view」 ......感謝您的回覆 – Boubou95

+0

但是,你只會調用呈現內解僱查看,這不會是你的AppDelegate。在這裏調用它,而不是回叫你的AppDelegate去做。 –

+0

同樣的事exc_bad_access。在我的AddDelegate中,我使用:[self dismissModalViewControllerAnimated:YES]在loginViewController中調用一個函數。 – Boubou95

0

的EXC_BAD_ACCESS意味着你試圖訪問的東西,已經被釋放了。我認爲你不需要回調你的loginViewController就可以解除模態視圖。只要發佈當前的觀點,你的其他觀點應該在那裏等着你。

[self.view dismissModalViewControllerAnimated:YES]; 
+0

我不能做這個因爲自己是我的_AppDelegate * _,所以沒有「self.view」,謝謝你的回覆 – Boubou95

+0

我認爲UIView不響應'dismissModalViewControllerAnimated:YES' –

相關問題