iOS UIAlertController 使用介绍
2016-03-11 11:43
363 查看
1.粘贴复制的同学 请长脑,我这段代码是在view内写的,所以会有一个通过响应者链找controller的代码
// 初始化一个一个UIAlertController // 参数preferredStyle:是IAlertController的样式 // UIAlertControllerStyleAlert 创建出来相当于UIAlertView // UIAlertControllerStyleActionSheet 创建出来相当于 UIActionSheet UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否取消订单?" preferredStyle:(UIAlertControllerStyleAlert)]; // 创建按钮 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { NSLog(@"确定"); }]; // 注意取消按钮只能添加一个 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { // 点击按钮后的方法直接在这里面写 NSLog(@"取消"); }]; //创建警告按钮 // UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) { // NSLog(@"警告"); // }]; //添加按钮 将按钮添加到UIAlertController对象上 [alertController addAction:okAction]; [alertController addAction:cancelAction]; // [alertController addAction:structlAction]; //将UIAlertController模态出来 相当于UIAlertView show 的方法 UINavigationController *viewController = [self findViewController:self]; [viewController presentViewController:alertController animated:YES completion:nil]; //通过View找viewController - (UINavigationController *)findViewController:(UIView *)sourceView { id target= sourceView; while (target) { target = ((UIResponder *)target).nextResponder; if ([target isKindOfClass:[UINavigationController class]]) { break; } } return target; }
相关文章推荐
- suricata Quick Start Guide 启动手册
- UIView的Touch事件UIControlEvents详解
- HDU 2604 Queuing(矩阵快速幂)
- UI--手势识别器
- 《iOS Human Interface Guidelines》——Container View Controller
- Scene is unreachable due to lack of entry points and does not have an identifier for runtime access
- 如何解决androidstudio build项目png的iCCP警告
- "build gradle project info" Android Studio 导入Gradle工程时引发该问题的解决办法
- String.valueOf() 方法的使用
- 放在UIImageView上 按钮不能点击
- Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支持蓝牙4.0版本_BLE开发
- Contacts.CONTENT_STREQUENT_URI和Contacts.CONTENT_FREQUENT_URI
- UIImageView 图片变得模糊朦胧问题
- .Net自带ChartControl报错:Auto interval does not have proper value
- IOS-CAShapeLayer与UIBezierPath的基本用法
- RequireJS 依赖关系的实例
- hdu4893Wow! Such Sequence! (线段树)
- 96 - Unique Binary Search Trees
- jboss中调用Tuexdo服务遇到的问题 - JBAS014671
- 在 UITableView 上加手势(UITableView上点击键盘消失)