exc_bad_access dismissModalViewControllerAnimated
I'm new in iPhone SDK dev, and I'm not an englishman, so my apologies for my level.
Here is my problem: I've a tabBarcontroller, with 3 item, each has a 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.windo开发者_如何学运维w makeKeyAndVisible];
[self.tabBarController release];
if ([self respondsToSelector:@selector(loginViewControllerLogout:)]) {
[self performSelector:@selector(loginViewControllerLogout:) withObject:[self loginViewController]];
}
return YES;
Here this is the selector
-(void)loginViewControllerLogout:(LoginViewController *)loginViewController {
if (![self.loginViewController logguedIn])
[self.tabBarController presentModalViewController:self.loginViewController animated:YES];
}
And When I'm loggued, I call:
-(void)loginViewControllerDidFinish:(LoginViewController *)loginViewController {
[self.loginViewController dismissModalViewControllerAnimated:YES];
}
These piece of code work when the App is launching for the first time. LoginViewController displayed > login successfull > LoginViewcontroller dismiss > FirstViewController displaying. But if I go to the thirdViewController, click on logout: selector LoginViewControllerLogout called > LoginViewController displayed > Login successfull > Crash in the dismissModal.
There is no error stack, just the exc_bad_access error. There is more than 1 retain for loginViewController.
Thanks in advance
EDIT: all functions are in the AppDelegate
instead of
[self.tabBarController presentModalViewController:self.loginViewController animated:YES];
try this
[self presentModalViewController:self.loginViewController animated:YES];
this should work as you are presenting modal in your window and not tabbar..
or
[self presentModalViewController:loginViewController animated:YES];
The EXC_BAD_ACCESS means you are trying to access something that has been released already. I'm thinking you don't need to call back to your loginViewController to just dismiss the modal view. Just release the current view and your other view should be there waiting for you.
[self.view dismissModalViewControllerAnimated:YES];
精彩评论