在IOS9.0中,摒弃了IOS中的UIAlertView控件。所以以往的方法不能使用;下面是在IOS9.0中创建Alert控件的Source Code:
UIAlertController *alt = [UIAlertController alertControllerWithTitle:@"提示"
message:@"输入错误"preferredStyle:UIAlertControllerStyleActionSheet];
[alt addAction:[UIAlertAction actionWithTitle:@"取消"
style:(UIAlertActionStyleCancel)
handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alt animated:YES completion:nil];其中preferredStyle是一个枚举类型(只包含两种):UIAlertControllerStyleActionSheet、UIAlertControllerStyleAlert;
一个是从底部弹出,一个是中间显示;
handler、completion:是点击取消按钮后需要执行的代码,可以设置为nil;
如果还要添加其他的按钮:
UIAlertAction *addNo = [UIAlertAction actionWithTitle:@"其他"
style:UIAlertActionStyleDefault
handler:nil];
[alt addAction:addNo];
本文介绍了如何在iOS9中使用UIAlertController替代UIAlertView来创建弹出框。提供了具体的代码示例,包括如何设置标题、消息、样式及添加按钮等。
1168

被折叠的 条评论
为什么被折叠?



