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

现在已经不用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];
 //为按钮增加目标,响应事件????
 
}

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

阅读 6.9k
2 个回答

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

+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题