iOS被替换的方法及其更新方法

弹窗


- (IBAction)doClick:(UIButton *)sender {
    
    
    UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"随便按" message:@"让你按你就按" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"选项1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"click001");
    }];
    [alertC addAction:action1];
    
    UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"选项2" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"click002");
    }];
    [alertC addAction:action2];
    
    UIAlertAction * action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    [alertC addAction:action3];
    
    [self presentViewController:alertC animated:YES completion:nil];
    
}
  • 该方法于iOS8推出,并代替UIAlertViewUIActionSheet两种方法,分别用创建时的preferredStyle来代表前两种方法:UIAlertControllerStyleActionAlertUIAlertControllerStyleActionSheet
  • 对应选项的响应分别在UIAlertAction的block内部实现。
alert
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容