iOS中UIAlertView怎么用

这篇文章主要介绍iOS中UIAlertView怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

NS_CLASS_DEPRECATED_IOS(2_0, 9_0, "UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead") __TVOS_PROHIBITED

大概意思是说9以后用UIAlertController代替UIAlertView,9以前还是UIAlertView

double version = [[UIDevice currentDevice].systemVersion doubleValue];//判定系统版本。

    if(version>=9.0f){

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:UIAlertControllerStyleAlert];

        [alertController addAction: [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            NSLog(@"确定");

        }]];

        [alertController addAction: [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            NSLog(@"取消");

        }]];

        [self presentViewController:alertController animated:YES completion:nil];

    }else{

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",@"取消", nil];

        [alertView show];

    }

#pragma mark UIAlertView 点击事件

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0){

    NSLog(@"%@",@(buttonIndex));

}

以上是“iOS中UIAlertView怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!