我有一个很大的问题。我正在尝试UITableViewCell
在UITableView
. 这很好用,我目前在按下时执行了一个动作和选择器。
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;
和选择器:
- (void) didTapStar {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:/* indexPath? */];
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;
}
现在,问题来了:我想知道按下的附件属于哪一行。我怎样才能做到这一点?
谢谢 :)