1

I have a UIButton,

-(void)backBtn:(NSString *)parentId lbltext:(NSString *)label

function will be fired when push the button,

[button addTarget:self 
           action:@selector(backBtn:lbltext:) 
       withObject:par 
       withObject:title.text 
 forControlEvents:UIControlEventTouchDown]; 

I looked this question. But my fired function will change my button name, depends some functions with the parameters. So I can't create another class.

How can I make this code true?Thanks.

Community
  • 1
  • 1
e.ozmen
  • 269
  • 3
  • 17

1 Answers1

3

I would use a delegate for this instead. Trigger the event in your own class and then send it using a delegate. Also, UIControlEventTouchUpInside is better, UIControlEventTouchDown will be triggered even if the user regrets its action (by moving the finger outside the button).

- (void) touchEvent:(id)sender {
    if ([self.delegate respondToSelector@selector(par:text)]) {
        [self.delegate par:something text:@"MyText"];
    }
}
Konrad77
  • 2,515
  • 1
  • 19
  • 36
  • Thanks for replying. I created the UIButton with code. So am I gonna put the touchEvent into the action:@selector? – e.ozmen Aug 15 '13 at 08:26