UIAlertController 大坑

      项目中在使用UIAlertController的时候发现点击空白处无法取消控件,添加手势也无法识别,后来发现使用这个控件的时候必须添加唯一的一个取消按钮。即必须有一项是UIAlertActionStyleCancel类型的按钮。如果有2项会报错,如果没有,点击空白处控件无法消失。


  UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"变动类型" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    
   
    [alertController addAction:[UIAlertAction actionWithTitle:@"兑换" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"点击确认");
        
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"退货" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"点击确认");
        
    }]];

    // 由于它是一个控制器 直接modal出来就好了
    
    [self presentViewController:alertController animated:YES completion:nil];
爱code的妖妖
原文地址:https://www.cnblogs.com/yaoyao0110/p/6228450.html