【发布时间】:2014-01-09 18:50:32
【问题描述】:
我想在有人按下我的 iOS 应用程序的“返回”按钮时添加一个弹出窗口,询问用户是否真的想回来。然后,根据用户的响应,我想撤消操作或继续。我尝试在视图的 viewWillDisappear 函数中添加代码,然后编写正确的委托,但它不起作用,因为它总是更改视图然后显示弹出窗口。我的代码是:
-(void) viewWillDisappear:(BOOL)animated {
_animated = animated;
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
UIAlertView *alert_undo = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:@"You could be loosing information with this action. Do you want to proceed?"
delegate:self
cancelButtonTitle:@"Go back"
otherButtonTitles:@"Yes", nil];
[alert_undo show];
}
else [super viewWillDisappear:animated];
}
委托实现是:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Yes"])
{
[super viewWillDisappear:_animated];
}
}
这根本不起作用。现在有没有人有更好的方法来做到这一点或可能出了什么问题?
非常感谢,
【问题讨论】:
标签: ios objective-c popup viewcontroller