ios - 现在已经不用UIAlertView了,但是如何为UIAlertController添加目标,来相应事件?
迷茫
迷茫 2017-04-17 17:44:10
[iOS讨论组]

现在已经不用UIAlertView了,但是如何为UIAlertController添加目标,来相应事件?

之前是通过协议中的方法确定 按钮索引以此来相应事件,现在应该怎么做呢?

//删除按钮
-(void)delPerson:(UIButton*)sender{
   //点击删除应该显示警报:
    UIAlertController * d=[UIAlertController alertControllerWithTitle:@"你大爷的注意!" message:@"确定删除么?" preferredStyle:UIAlertControllerStyleAlert];
    //为警报添加按钮
    UIAlertAction * a1=[UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction * a2=[UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:nil];

    //^(UIAlertAction * a1) {}
    //将按钮添加到警报控件上
    [d addAction:a1];
    [d addAction:a2];
    //警报视图控制器呈现出来
    [self presentViewController:d animated:YES completion:nil];
 //为按钮增加目标,响应事件????
 
}

我怎么能确定我点击了那个按钮?而让其触发事件?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(2)
巴扎黑

好好看下初始化方法,handler 就是触发执行的 block ,你都置 nil 了==

+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler
怪我咯

可以看一看我专栏里的文章《从UIAlertView、UIActionSheet到UIAlertController》。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号