tags:

views:

183

answers:

2

Hi,

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

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

Thanks

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

…   

- (void)method1and2 {
    [self method1];
    [self method2];
}
coneybeare
But he has 2 different events? This is what I thought first also, but it doesn't work for the question.
marcc
you are right. i should have scrolled the code to the right.
coneybeare
+2  A: 

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?

mahboudz
yeah it worked, i just forgot the IBAction. thanks
sasayins