http://www.jianshu.com/p/bd981a4484da
使用简介
简单封装
新建一个UIAlertController分类
添加分类方法,由外界提供提示信息、及需要执行的操作,返回一个UIAlertController对象
-(UIAlertController *)showTipInfo:(NSString *)title subTitle:(NSString *)detail okBlock:(void(^)())aBlock noBlock:(void(^)())bBlock{
//1、创建弹框
UIAlertController *aler = [UIAlertController alertControllerWithTitle:title message:detail preferredStyle:UIAlertControllerStyleAlert];
//2、创建按钮
UIAlertAction *alerBtn1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(aBlock)
aBlock(); // 确定的相关处理
return ;
}];
//3、创建确定按钮
UIAlertAction *alerBtn2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
if(bBlock)
bBlock(); // 取消的相关处理
return ;
}];
[aler addAction:alerBtn2];
[aler addAction:alerBtn1];
return aler;
}
外界方便使用
#pragma mark -创建弹框提示
-(void)showLoginTip{
// 定义block,点击确定时 执行的动作
void(^loginBlock)() = ^() {
PDloginViewController *vc = [[PDloginViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
};
UIAlertController *aler = [[UIAlertController alloc] showTipInfo:@"请先登录" subTitle:nil okBlock:loginBlock noBlock:nil];
[self presentViewController:aler animated:YES completion:nil]; //显示弹框
}