如何在ios uialertactionn上添加函数事件

现在已经不用UIAlertView了,但是如何为UIAler - 跟谁学
搜索你想学的科目、老师试试,例如“舞蹈”搜索吉安
&&现在已经不用UIAlertView了,但是如何为UIAler现在已经不用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];
//为按钮增加目标,响应事件????
} 我怎么能确定我点击了那个按钮?而让其触发事件?文艺青年阿虚Vzxming
好好看下初始化方法,handler 就是触发执行的 block ,你都置 nil 了==+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler
可以看一看我专栏里的文章《》。
相关问题大家都在看最新提问
关注我们官方微信关于跟谁学服务支持帮助中心一、动态添加Button
动态添加Button的效果就是点击之后,生成一个按钮,并为按钮添加点击的方法。
1、在xib文件上拖拽添加一个button,标题为:添加button。
2、按住ctrl键拖拽到addbuttonViewController.m文件空白处,生成IBAction,填充代码后如下:
- (IBAction)addButton:(id)sender {
CGRect frame = CGRectMake(90, 200, 200, 60);
UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
someAddButton.backgroundColor = [UIColor clearColor];
[someAddButton setTitle:@"动态添加一个按钮!" forState:UIControlStateNormal];
someAddButton.frame =
[someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:someAddButton];
3、动态生成的button点击事件方法:
生成的button点击弹出提示框。
-(void) someButtonClicked{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"您点击了动态按钮!"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
4、编译运行效果 图1 2 3:
点击按钮后
二、监听UIAlertView。
1、在上面的代码基础上,在addbuttonViewController.h文件添加委托
#import &UIKit/UIKit.h&
@interface addbuttonViewController : UIViewController&UIAlertViewDelegate&
- (IBAction)addButton:(id)
3、在对应的.m文件中实现委托中的方法
监听你点击了那个按钮
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
NSLog(@"buttonIndex:%d", buttonIndex);
点击AlertView中弹出的三个按钮打印的结果:
2012-06-14 16:53:18.516 DynamicAddButton[5645:f803] buttonIndex:1
2012-06-14 16:53:23.652 DynamicAddButton[5645:f803] buttonIndex:2
2012-06-14 16:53:25.701 DynamicAddButton[5645:f803] buttonIndex:0
2012-06-14 16:53:39.900 DynamicAddButton[5645:f803] buttonIndex:1
这样你就知道点了按个按钮了。
程序源码下载:gitbub: &/schelling/YcDemo/tree/master/DynamicAddButton1
& & & & & & & & & & & & & & csdn资源:
阅读(...) 评论()&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
现在已经不用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];
//为按钮增加目标,响应事件????
我怎么能确定我点击了那个按钮?而让其触发事件?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
可以看一看我专栏里的文章《》。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
好好看下初始化方法,handler 就是触发执行的 block ,你都置 nil 了==
+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler
分享到微博?
Hi,欢迎来到 SegmentFault 技术社区!⊙▽⊙ 在这里,你可以提出编程相关的疑惑,关注感兴趣的问题,对认可的回答投赞同票;大家会帮你解决编程的问题,和你探讨技术更新,为你的回答投上赞同票。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
扫扫下载 App
SegmentFault
一起探索更多未知}

我要回帖

更多关于 uialertaction 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信