【发布时间】:2011-02-03 11:00:53
【问题描述】:
我有一个很大的问题。我正在尝试在UITableView 中的每个UITableViewCell 上创建一个收藏按钮。这很好用,我目前在按下时执行了一个动作和选择器。
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;
}
现在,问题来了:我想知道按下的附件属于哪一行。 我该怎么做?
谢谢你:)
【问题讨论】:
-
看看这个:简单、快速和容易。 stackoverflow.com/a/55156685/5846076
标签: iphone uitableview ios4 row accessory