Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass argument in @selector?

How can I pass an argument in the @selector for my code below?

[thisIconBtn addTarget:self action:@selector(changeIconState) forControlEvents:UIControlEventTouchUpInside];

-(void)changeIconState:(UITableViewCell*)thisCell
{
  //do something
}
like image 505
Zhen Avatar asked Jun 05 '11 12:06

Zhen


1 Answers

First, the colon is part of the selector: @selector(changeIconState:).

Second, actions are methods that take a particular set of parameters — you can't just use any method as an action. Usually, actions look like this:

- (void)myAction:(id)sender;

where sender is a pointer to the object that's sending the action. In your code, when thisIconButton is tapped, that button would be passed as the sender.

like image 105
Caleb Avatar answered Nov 12 '22 09:11

Caleb