首先,这是一些代码:
- (void)viewDidLoad
{
[super viewDidLoad];
FirstViewController *first = [[FirstViewController alloc] init];
SecondViewController *second = [[SecondViewController alloc] init];
MBPullDownController *pullDownController = [[MBPullDownController alloc] initWithFrontController:first backController:second];
[self.navigationController addChildViewController:pullDownController];
}
- (void)pushAnotherViewController:(NSNotification *)notification
{
AnotherViewController *another = [self.storyboard instantiateViewControllerWithIdentifier:@"anotherViewController"];
[self pushScheduleViewController:another];
}
我使用MBPullDownController 开源控件。使用分离 View Controller 我加载到下拉 Controller 。此代码位于名为 RootViewController 的 View Controller 中,该 View Controller 嵌入到 UINavigationController 中。然后是在导航 Controller 中推送另一个 View Controller 的方法。当我尝试使用方法(在 AnotherViewController 中)popToRootViewController:
时,我的应用程序崩溃并且 EXC_BAD_ACCESS 消息出现在控制台中。
编辑
这是我在“AnotherViewController”中的代码
- (void)popBack
{
RootScheduleViewController *root = [[RootScheduleViewController alloc] init];
[self.navigationController popToViewController:root animated:YES];
}
最佳答案
当您调用 popBack
时遇到错误访问错误,因为您正在创建 View Controller 的新实例,然后尝试弹出到它。对于导航 Controller , View Controller 必须是导航堆栈的一部分才能弹出。因此,如果此 View Controller 的实例存在,请在导航堆栈中找到它并弹出它。
for(UIViewController * viewController in self.navigationController.viewControllers){
if([viewController isKindOfClass:[RootScheduleViewController class]]){
[self.navigationController popToViewController:viewController animated:NO];
break;
}
}
关于ios - 弹回 View Controller 时使用 ARC 的 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21099131/