美文网首页iOS
iOS被替换的方法及其更新方法

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

作者: 清都 | 来源:发表于2017-08-18 11:45 被阅读29次

弹窗


- (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

相关文章

网友评论

    本文标题:iOS被替换的方法及其更新方法

    本文链接:https://www.haomeiwen.com/subject/ogzorxtx.html