alertControllerWithTitle:@"照片" message:@"拍照或者从相册中选择照片" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDestructive handler:^(UIAlertAction ; }else { NSLog(@"模拟其中无法打开照相机,请在真机中使用"); } }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction
"上传照片" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction handler:^(UIAlertAction * _Nonnull action) { handler:^(UIAlertAction * _Nonnull action) { handler:^(UIAlertAction * _Nonnull action) { "上传视频" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction
alertControllerWithTitle:@"提示" message:@"确定要这样做么" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@ "确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }];
我们需要在UIAlertController提示器添加一个按钮时,先创建一个UIAlertAction,然后通过UIAlertController的 addAction: 方法将创建的UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull ]; //销毁按钮 UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"Destructive" style :UIAlertActionStyleDestructive handler:nil]; //取消按钮 UIAlertAction *cancelAction = [UIAlertAction
UIAlertAction * _Nonnull action) { }]; UIAlertAction *pickAction = [UIAlertAction actionWithTitle UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel UIAlertAction * _Nonnull action) { }]; UIAlertAction *commentAction = [UIAlertAction }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel * _Nonnull action) { }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle
通过创建UIAlertAction的实例,您可以将动作按钮添加到控制器上。UIAlertAction由标题字符串、样式以及当用户选中该动作时运行的代码块组成。 Objective-C版本: UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style: UIAlertActionStyleCancel handler: nil]; UIAlertAction *okAction = [UIAlertAction actionWithTitle: @"好的" style: UIAlertActionStyleDefault Objective-C版本: UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style: UIAlertActionStyleDefault 比如说在okAction这个按钮动作中: Objective-C版本: UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的
*sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction (@"点击了【随便1】按钮"); }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"随便2" style :UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"点击了【随便2】按钮"); }]]; preferredStyle:UIAlertControllerStyleAlert]; // 添加按钮 UIAlertAction *sure = [UIAlertAction actionWithTitle preferredStyle:UIAlertControllerStyleAlert]; // 添加按钮 UIAlertAction *sure = [UIAlertAction actionWithTitle
: @"" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * action = [UIAlertAction actionWithTitle :@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { completionHandler : @"" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * cancelAction = [UIAlertAction completionHandler(NO); }]; UIAlertAction * confirmAction = [UIAlertAction actionWithTitle * action = [UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction
title = maps[i][@"title"]; //苹果原生地图方法 if (i == 0) { UIAlertAction * action = [UIAlertAction actionWithTitle:title style:(UIAlertActionStyleDefault) handler:^(UIAlertAction [alert addAction:action]; continue; } UIAlertAction * action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction
*sure = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *savePhoto = [UIAlertAction actionWithTitle:@"保存到相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *openPhoto = [UIAlertAction actionWithTitle:@"打开相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *turnonCamer = [UIAlertAction actionWithTitle:@"打开相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction
另一个机制改变的地方是,其中按钮的触发方法不再通过代理处理,而是将按钮封装成了类:UIAlertAction。 actionWithTitle:@"仔细看" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction 三、UIAlertController其他属性和方法 @property (nonatomic, readonly) NSArray<UIAlertAction *> *actions; 获取所有AlertAction @property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0); iOS9后新增加的属性
UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction [self presentViewController:camera animated:YES completion:nil]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction
*refuseAction = [UIAlertAction actionWithTitle:@"? 残忍拒绝" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { [userDefaults setObject *okAction = [UIAlertAction actionWithTitle:@"? *showAction = [UIAlertAction actionWithTitle:@"? 我要吐槽" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { if (udUserChoose<=3 |
actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { :@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }])]; [alertController addAction:([UIAlertAction actionWithTitle:@"打开" style:UIAlertActionStyleDefault handler actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
URLWithString:mapSchemeArr[i]]; if ([[UIApplication sharedApplication] canOpenURL:url]) { UIAlertAction *action = [UIAlertAction actionWithTitle:mapName[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction mapName[i] toCoor:toCoor targetName:targetName]; }]; [alert addAction:action]; } } UIAlertAction *actionSystem = [UIAlertAction actionWithTitle:@"系统地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
(title: "取消", style: UIAlertAction.Style.cancel) { (action:UIAlertAction) in //取消 completionHandler (false) } alertView.addAction(cancelAction) let okAction = UIAlertAction.init(title: "确定", style : UIAlertAction.Style.default) { (action:UIAlertAction) in //确定 completionHandler(true) textField:UITextField) in //设置textField相关属性 textField.textColor = UIColor.red } let okAction = UIAlertAction.init (title: "确定", style: UIAlertAction.Style.destructive) { (action:UIAlertAction) in
preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * openAction = [UIAlertAction actionWithTitle :@"打开" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [device * cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * openAction = [UIAlertAction * cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction
preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * openAction = [UIAlertAction actionWithTitle :@"打开" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [device * cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * openAction = [UIAlertAction * cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction
*cameraAction = [UIAlertAction actionWithTitle:@"照相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction completion:nil]; }else{ NSLog(@"哎呀,没有摄像头"); } }]; //从手机相册选取 UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction completion:nil]; } else{ NSLog(@"图片库不可用"); } }]; //取消 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertController(title: "请选择", message:nil, preferredStyle: .ActionSheet) //取消按钮 let cancelAction: UIAlertAction (cancelAction) //拍照 let takePictureAction: UIAlertAction = UIAlertAction(title: "拍照", style: .Default = UIAlertAction(title: "相册", style: .Default) { action -> Void in [self .initWithImagePickView("相册") ] } actionSheetController.addAction(choosePictureAction) //摄像 let moviePictureAction: UIAlertAction = UIAlertAction(title: "摄像", style: .Default) { action -> Void in [self .initWithImagePickView("摄像")]