![](/img/trans.png)
[英]UIButton with custom view - addTarget:action:forControlEvents: does not work
[英]UIButton addTarget:action:forControlEvents: not working using itself as a target?
有一个UIButton
的子类,是否可以使用按钮本身为按钮添加目标? 例如
[self addTarget:self action:@selector(onClick:forEvent:) forControlEvents:UIControlEventTouchUpInside];
是的,只需改变这个:
[self addTarget:self action:@selector(onClick:forEvent:) forControlEvents:UIControlEventTouchUpInside];
对此:
[MyButton addTarget:self action:@selector(onClick:forEvent:) forControlEvents:UIControlEventTouchUpInside];
它没有工作bcoz你是添加自我作为目标。 您需要将ViewController添加为添加按钮的目标。
[self addTarget:viewController action:@selector(onClick:forEvent:) forControlEvents:UIControlEventTouchUpInside];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.