开发者

How can I add multiple actions to a UIButton

开发者 https://www.devze.com 2022-12-11 18:43 出处:网络
How can I add multiple action in a single UIButton? Life for example, [btn addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];

How can I add multiple action in a single UIButton? Life for example,

[btn addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
[btn addTarget:self actio开发者_开发问答n:@selector(method2) forControlEvents:UIControlEventTouchDown];

Thanks


The code you have pasted should work:

[btn addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
[btn addTarget:self action:@selector(method2) forControlEvents:UIControlEventTouchDown];

I do this all the time. Usually for touchDown and touchUp. The fact that method2 isn't getting called is a bug. Do you have an NSLog() at the beginning of method2?


[btn addTarget:self action:@selector(method1and2) forControlEvents:UIControlEventTouchUpInside];

…   

- (void)method1and2 {
    [self method1];
    [self method2];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消