当 UITabBarControllerDelegate 调用时 popToRootViewController 崩溃
我有一个带有 4 个 UINavigationControllers 的 UITabBarController。我已经实现了 didSelectViewController
委托方法,如下所示:
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([viewController isKindOfClass:[UINavigationController class]]) {
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
}
在 didSelectRowAtIndexPath
将新的 viewController 推入堆栈后,当 NavigationController
处于第二级时,它会崩溃。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
// ...
detailViewController.title = [self.temp objectAtIndex:indexPath.row];
detailViewController.sort = self.title;
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
当然,启用了 NSZombies
的调试器不会给出任何反馈。
但是,如果我将保留添加到detailViewController alloc;
RootViewController *detailViewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] retain];
它可以工作,但会泄漏内存。
任何想法出了什么问题,如何解决,发生了什么?
I have a UITabBarController
with 4 UINavigationControllers
. I have implemented the didSelectViewController
Delegate Method as follows:
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([viewController isKindOfClass:[UINavigationController class]]) {
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
}
It crashes when a NavigationController
is at a 2nd Level after didSelectRowAtIndexPath
pushes a new viewController onto the stack.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
// ...
detailViewController.title = [self.temp objectAtIndex:indexPath.row];
detailViewController.sort = self.title;
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
Of course the debugger with NSZombies
enabled doesn't give any feedback.
However, if I add retain to detailViewController alloc;
RootViewController *detailViewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] retain];
It works, but leaks memory.
Any ideas what is wrong, how to fix, what is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的情况,我想出了以下解决方案。
在我的应用程序中,我在启动时有登录屏幕,然后我有带有 4 个 UINavigationController 的 UITabbarController。
我在 AppDelegate.h 文件中创建了 UINavigationController 的属性。
然后
现在当您需要弹出到 RootViewController 时,请使用以下代码
希望这可以解决您的问题。
I have the similar scenario and i came up with following solution.
In my application i have login screen at launch and then I have UITabbarController with 4 UINavigationControllers.
I have created property of UINavigationController in AppDelegate.h file.
Then
Now when you need to pop to RootViewController then use following code
Hope this solves your problem.