创建一个对话框、操作表
//创建一个UIAlertController 对话框 并指定标题和内容 preferredStyle:指定样式(nil就是为默认样式 也就是操作表的样式)
UIAlertController *uiAlertController =
[UIAlertController alertControllerWithTitle:@"提示框" message:@"what???"preferredStyle:UIAlertActionStyleCancel];
//创建一个操作表 或者用这样的方式创建:使用上方的初始化方式 且参数都设为nil)
IAlertController *sheetController =[[UIAlertController alloc]init];
style:
UIAlertActionStyleDefault:默认样式(蓝色字体)
UIAlertActionStyleCancel:取消样式
创建按钮并添加到UIAlertController
//创建取消按钮 指定按钮文本、按钮样式和点击后的操作
UIAlertAction *noAction =
[UIAlertAction actionWithTitle:@"No"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
NSLog(@"用户取消操作");
}];
UIAlertAction *yesAction =
[UIAlertAction actionWithTitle:@"Yes"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
NSLog(@"确定");
}];
//将创建的两个按钮添加到对话框
[uiAlertController addAction:noAction];
[uiAlertController addAction:yesAction];
按钮多一种style: UIAlertActionStyleDestructive: 警告样式(红色字体)
显示对话框
[self presentViewController:uiAlertController animated:true completion:nil];