iOS9 xcode7以后,很多方法都过期了,被新的方法所代替。在这里我主要介绍两个常用的控件——UIAlertView、UIActionSheet被替代的新控件——UIAlertController的使用。
一、UIAlertController的UIActionSheet效果时的用法
UIAlertController * sheet = [UIAlertController alertControllerWithTitle:nil message:@"选择性别" preferredStyle:UIAlertControllerStyleActionSheet];
[sheet addAction:[UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
NSLog(@"在这里处理选择之后的事");
}]];
[sheet addAction:[UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
NSLog(@"在这里处理选择之后的事");
}]];
[sheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:sheet animated:YES completion:nil];
二、UIAlertController的UIAlertView效果时的用法
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入手机号" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"确定"style:(UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {
NSLog(@"在这里处理点击按钮之后的事");
}];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];