I want to place a button in each cell of a table. I want the target to be a class that I'm using to handle all of the API calls. I want the button's method to be in the friendController class, not in the UITableView's View Controller.
[cell.deleteButton addTarget:friendController
action:@selector(deleteFriend: forID:cell.idNumber)
forControlEvents:UIControlEventTouchUpInside];
Where friendController
is the class with the API calls, and cell.idNumber is an instance variable of each cell containing the ID number of the user associated with that cell.
I know (well, I presume) that I could set the cell itself as the target and then have a method which looks like:
-(IBAction)deleteFriend:(id)sender {
[friendController deleteFriend:self.idNumber];
}
Is that correct? It doesn't seem like an elegant way of doing this. Is there a way to do it the way I want to, or is there a better way to do it?
EDIT: I emboldened the last crucial part of my question. I want the button's action to be a method in another class (friendController). friendController is a class I created to house all of the API calls and business logic. If I set the target to friendController, must the action be a method in that class?