该应用程序以viewController1开头 . 我有一个标准的push segue到viewController2,然后另一个push segue从viewController2到viewController3 . 在viewController3中,我有一个自定义后退按钮,我想将用户发送回viewController2(或者返回到viewController1也可以) .

自定义后退按钮代码是这样的:

- (IBAction)customBackButton:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

这作为viewController2的后退按钮(如果我从viewController1转到viewController2,并在viewController2中使用此代码,它成功地将我带回viewController1) . 但是,当我在viewController3中使用它时,我收到此错误:

Terminating app due to uncaught exception 'NSRangeException', reason: '*** - [__NSArrayI objectAtIndex:}: index 0 beyond bounds for empty array'

有没有更好的方法来做自定义后退按钮?我不想让它成为另一个推送segue回到viewController2,因为这似乎保留了viewController3对象,然后我回到viewController 3(在点击自定义后退按钮之后)功能上搞砸了 .