UITableViewCell定制配件 - 获取一排配件 [英] UITableViewCell Custom accessory - get the row of accessory
本文介绍了UITableViewCell定制配件 - 获取一排配件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很大的问题。我想在 UITableView
中的每个 UITableViewCell
上创建一个收藏夹按钮。这非常好,我按下时会执行一个动作和选择器。
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;
选择器:
- (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;
}
现在,问题在于:我想知道附件是什么排按下属于。
我该怎么做?
Now, here's the problem: I want to know what row the accessory that was pressed belongs to. How can I do this?
谢谢:)
推荐答案
我会使用以下代码:
- (void)didTapStar:(id)sender {
NSIndexPath *indexPath = [tableView indexPathForCell:(UITableViewCell *)[sender superview]];
}
这篇关于UITableViewCell定制配件 - 获取一排配件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文