我是iPhone SDK开发人员的新手,我不是英国人,所以我为自己的水平道歉。
这是我的问题: 我有一个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];
}
当我被记录时,我打电话给:
-(void)loginViewControllerDidFinish:(LoginViewController *)loginViewController {
[self.loginViewController dismissModalViewControllerAnimated:YES];
}
这些代码在应用程序首次启动时起作用。 LoginViewController显示>登录成功> LoginViewcontroller dismiss> FirstViewController显示。 但是,如果我转到thirdViewController,请单击logout: 选择器LoginViewControllerLogout调用> LoginViewController显示>登录成功>在dismissModal崩溃。
没有错误堆栈,只有exc_bad_access错误。 loginViewController有多于1个保留。
提前致谢
编辑:所有功能都在AppDelegate
中答案 0 :(得分:0)
而不是
[self.tabBarController presentModalViewController:self.loginViewController animated:YES];
试试这个
[self presentModalViewController:self.loginViewController animated:YES];
这应该适用于你在窗口中呈现模态而不是tabbar ..
或
[self presentModalViewController:loginViewController animated:YES];
答案 1 :(得分:0)
EXC_BAD_ACCESS表示您正在尝试访问已经发布的内容。我想你不需要回调你的loginViewController来解除模态视图。只需发布当前视图,您的其他视图就在那里等着您。
[self.view dismissModalViewControllerAnimated:YES];