您的位置:首页 > 产品设计 > UI/UE

ios基本控件之UIAlertController

2016-06-16 14:59 316 查看
在IOS8以后我们就可以用这个UIAlertController了,本人感觉用惯了UIAlertView,还真的有点不习惯这个 UIAlertController,所以自己用警告狂的时候基本用的都还是 UIAlertView,可是在IOS9之后这个UIAlertView就要被放弃了,昨天IOS10刚出来,那我现在就得把项目中自己用到的这个UI AlertView 修改成这个controller了,今天在用的时候,我发现给这个controller添加事件的时候取消永远是在前边,这看着会不会太奇葩了,

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

//do sure action

}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

//do cancel action

}];

[alertController addAction:sureAction];

[alertController addAction:cancelAction];

这样的话,取消在前边,如下图:


好吧 奇葩,所以我想着是不是这个cancel有问题,所以我这么写:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"输入数值不符合规则,请重新输入" preferredStyle:UIAlertControllerStyleAlert];

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

//do sure action

}];

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

//do cancel action

}];

[alertController addAction:sureAction];

[alertController addAction:cancelAction];

[self.viewController presentViewController:alertController animated:YES completion:^{

}];

还真是,解决了问题:



以后得用这个AlertController,就像我之前写的关于App Store 的IPV6的事中的一句话,真是苹果打了哈欠,我们就感觉地动山摇啊。不关注苹果动向,随时的API可能就不能用了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: