-(void)cancelAction{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否确定放弃回复?" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES]; //这里写选择确定之后的操作
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@“用户选择继续”); //这里写选择取消之后的操作
}]];
}
当需要弹窗提示选择时,可以调用此方法,即简单创建和显示弹出窗。
上述代码是最简单的一种选择窗,即alertView。类似效果: