ios - target监听button点击,没有任何响应。

查看:157
本文介绍了ios - target监听button点击,没有任何响应。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

/** 创建btn */
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake((self.view.frame.size.width - 100)*0.5, 500, 100, 50);
btn.backgroundColor = [UIColor greenColor];
btn.tintColor = [UIColor blackColor];
[btn setTitle:@"按住拍" forState:UIControlStateNormal];
[self.view addSubview:btn];

/** 监听事件 */
[btn addTarget:self action:@selector(touchDown) forControlEvents:UIControlEventTouchDown];

  • (void)touchDown {
    NSLog(@"按钮被按下");
    }

纯代码创建button,target监听button的点击事件,不明白为何点击button却没有任何响应。

解决方案

刚刚把你的代码拷贝一了下 运行,是可以的。点击button有反应。代码没问题。可能是的你是
1.你的父类禁止了交互(userInteractionEnabled)
2.也可能是有东挡住了,
3.也可以是你frme设置的父控件frme超出了、
4.xcode 抽筋了。

这篇关于ios - target监听button点击,没有任何响应。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆