UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"警告" message:@"看看我是谁" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"--------------");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"--------------");
}]];
[self presentViewController:alert animated:YES completion:^{
}];
它的优点: 1.可以直接使用在Block模块中调用确定或取消的方法,非常方便;
2. 由于苹果摒弃了UIAlertView,所以在项目中不会看到讨厌的黄色警告了;
缺点: [self presentViewController:alert animated:YES completion] 方法的调用,决定了只能在ViewController下使用。
老湿的弹框
UIAlertView *aler=[[UIAlertView alloc]initWithTitle:@"标题" message:@"内容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"好笑", nil];
[aler show];
优点: 可以适用于各种情况下弹框,没有限制
缺点: 调用确定或取消的方法时候,需要调用代理方法。