所以我在上学期的项目中为学校制作了一个照片编辑应用程序。当用户点击后退按钮(在编辑器模式下),在我的情况下称为“产品选择”时,我想弹出一个弹出窗口并说“你想删除所有内容并返回产品选择吗? “看看他们是否要放弃他们的工作,如果用户选择是,整个项目将被丢弃并将它们放回大厅。
我将这段代码放在哪里?我在min story board中找到了“Product Selection”按钮,但不知道该怎么做。
我要使用的弹出窗口的代码是:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification"
message:@"Do you want to delete everything and go back to product selection?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes"];
[alert show];
[alert release]
非常感谢任何帮助/智慧!
答案 0 :(得分:2)
我会创建一个“取消”UIBarButton
来执行自定义函数:
- (void)cancelTapped {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"Do you want to delete everything and go back to product selection?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes"];
[alert setTag:1];
[alert show];
}
并收听要返回的提醒:
- alertView:didDismissWithButtonIndex:
从那里,我会编写逻辑来隐藏页面并弹出视图。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (alertView.tag == 1 && buttonIndex == 1) {
// Delete data and return to lobby
[self.navigationController popViewControllerAnimated:YES];
}
}
答案 1 :(得分:0)
使用此委托方法(不要忘记在.h上添加UIAlertViewDelegate):
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"Do you want to delete everything and go back to product selection?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes"];
alert.cancelButtonIndex = 0;
[alert show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
// If user confirmed:
if (buttonIndex != 0) {
// Do what you need.
}
}