彈窗
- (IBAction)doClick:(UIButton *)sender {
UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"隨便按" message:@"讓你按你就按" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"選項(xiàng)1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"click001");
}];
[alertC addAction:action1];
UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"選項(xiàng)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
兩種方法缀拭,分別用創(chuàng)建時(shí)的preferredStyle
來(lái)代表前兩種方法:UIAlertControllerStyleActionAlert
涕癣、UIAlertControllerStyleActionSheet
峻村。 - 對(duì)應(yīng)選項(xiàng)的響應(yīng)分別在UIAlertAction的block內(nèi)部實(shí)現(xiàn)谷遂。
alert