弹窗
- (IBAction)doClick:(UIButton *)sender {
UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"随便按" message:@"让你按你就按" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"选项1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"click001");
}];
[alertC addAction:action1];
UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"选项2" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"click002");
}];
[alertC addAction:action2];
UIAlertAction * action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消");
}];
[alertC addAction:action3];
[self presentViewController:alertC animated:YES completion:nil];
}
- 该方法于iOS8推出,并代替
UIAlertView
和UIActionSheet
两种方法,分别用创建时的preferredStyle
来代表前两种方法:UIAlertControllerStyleActionAlert
、UIAlertControllerStyleActionSheet
。
- 对应选项的响应分别在UIAlertAction的block内部实现。