iOS基本控件之UIAlertController

        在IOS8以后我们就可以用这个UIAlertController了,本人感觉用惯了UIAlertView,还真的有点不习惯这个UIAlertController,所以自己用警告框的时候基本用的都还是UIAlertView,可是在IOS9之后这个UIAlertView就要被放弃了,昨天IOS10刚出来,那我现在就得把项目中自己用到的这个UIAlertView修改成这个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还有一点,之前没注意过,就是直接在controller中写几个textField,注意是几个,不是只能写一个,类似下图:

以后遇到这种需求,不用自定义了,系统都封号了,当然了,如果跟你的需求差别大的话还是需要自己封装的。alertView也有,不过只能最多有两个,由于以后不再用alertView,故在此不再赘述。

以后得用这个AlertController,就像我之前写的关于App Store 的IPV6的事中的一句话,真是苹果打了哈欠,我们就感觉地动山摇啊。不关注苹果动向,随时的API可能就不能用了。

Hope To Help You !

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容