最佳答案
我需要检测用户何时点击导航栏上的“后退”按钮,以便在出现这种情况时执行一些操作。我试图手动设置一个操作到这样的按钮,这样:
[self.navigationItem.backBarButtonItem setAction:@selector(performBackNavigation:)];
- (void)performBackNavigation:(id)sender
{
// Do operations
[self.navigationController popViewControllerAnimated:NO];
}
我首先将这些代码放在视图控制器本身,但是我发现 self.navigationItem.backBarButtonItem
似乎是 nil
,所以我将同样的代码移动到父视图控制器,这将前者推到导航堆栈。但我也没办法。我读过一些关于这个问题的文章,其中一些说选择器需要在父视图控制器上设置,但是对我来说它无论如何都不能工作... ... 我能做错什么呢?
谢谢