我找到了这个问题的许多旧答案,但它们都是 2 年以上的。
我想为左键添加监听器——“后退”键。我想显示 UIAlertView,然后等待响应 - 是/否。
在更新的 SDK 中是否可行?
最佳答案
是的,您可以通过以下方式自己捕获和处理后退按钮事件来做到这一点:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backButtonPressed:)];
您可以在方法中显示警报:
- (void)backButtonPressed:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notice" message:@"Going back?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok"];
[alert show];
}
然后在UIAlertDelegate方法中
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) { // Button index: Cancel = 0; Ok = 1;
[self.navigationController popViewControllerAnimated:YES];
}
}
关于objective-c - 导航 Controller 中 "Going back"的监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10757115/