2011-08-31 97 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' –

相关问题