[英]UIButton Touch event is not working
menuView= [[UIImageView alloc] initWithFrame:CGRectMake(0,411, 320,49)];
UIButton *test = [UIButton buttonWithType:UIButtonTypeCustom ];
test.frame = CGRectMake(0, 0, 80, 49);
[test addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:test];
[self.view addSubview:menuView];
I touch up inside (test ) button. 我在里面(测试)按钮触摸。 but is not working .
但是没有用。 why??
为什么??
Maybe you mixed buttonPressed:
with buttonPressed
. 也许你混合了
buttonPressed:
with buttonPressed
。
If you implement a method like 如果你实现了像这样的方法
- (void)buttonPressed
{
}
You need use 你需要使用
[test addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
Note : Pay attention on the colon . 注意 :注意结肠 。
But depending on what you have done, you need implement a method like 但是根据你所做的,你需要实现一个类似的方法
- (void)buttonPressed:(id)sender
{
}
for a cleaner solution you can try HMUIButtonOnTouch 为了更清洁的解决方案,您可以尝试HMUIButtonOnTouch
source: https://github.com/HelloMihai/HMUIButtonOnTouch 来源: https : //github.com/HelloMihai/HMUIButtonOnTouch
[self.myButton onTouchInside:^{
NSLog(@"button tap");
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.