UITableViewCell Custom accessory - get the row of accessory

Posted by Emil on Stack Overflow See other posts from Stack Overflow or by Emil
Published on 2010-04-01T16:44:03Z Indexed on 2010/04/01 17:23 UTC
Read the original article Hit count: 502

Filed under:
|
|
|
|

Hi.

I have a pretty big issue. I am trying to create a favorite-button on every UITableViewCell in a UITableView. That works very good, and I currently have an action and selector performed when pressed.

accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
accessory.frame = CGRectMake(0, 0, 15, 15);
accessory.userInteractionEnabled = YES;
[accessory addTarget:self action:@selector(didTapStar) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = accessory;

And selector:

- (void) didTapStar {
 UITableViewCell *newCell = [tableView cellForRowAtIndexPath:???];

 accessory = [UIButton buttonWithType:UIButtonTypeCustom];
 [accessory setImage:[UIImage imageNamed:@"stared.png"] forState:UIControlStateNormal];
 accessory.frame = CGRectMake(0, 0, 26, 26);
 accessory.userInteractionEnabled = YES;
 [accessory addTarget:self action:@selector(didTapStar) forControlEvents:UIControlEventTouchDown];
 newCell.accessoryView = accessory;
}

Now, here's the problem: I want to know what row the accessory that was pressed belongs to. How can I do this?

Thank you :)

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode