开发者

How can I add multiple actions to a UIButton

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜