如何在objective-c中为我的窗口中的关闭按钮分配操作? 例如,用户单击关闭按钮然后程序询问:“你真的想要关闭窗口吗?”
答案 0 :(得分:1)
如果要在Application中关闭视图之前添加消息,则需要在其中实现UIAlertView,不要忘记添加< UIAlertViewDelegate>在.h文件中
按下代码操作按钮;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message"
message:@"Do you really want to close the window?"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
如果您想在单击按钮时执行某些操作,请实现此委托方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked OK
if (buttonIndex == 0) {
// Write Close Code here.....
}
}
答案 1 :(得分:0)
定义uialertview
UIAlertView *message;
message= [[UIAlertView alloc] initWithTitle:@"LOGOUT!" message:@"Are you sure to Logout of This app?" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
case :
{
[message show];
vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"loginVC"];
[[SlideNavigationController sharedInstance] popAllAndSwitchToViewController:vc withCompletion:nil];
break;}
}
default:
break;
}