【发布时间】:2013-05-29 15:13:58
【问题描述】:
现在我有一个带有自定义 UITableViewCell 的 UITableView,其中包含 2 个辅助按钮。
当其中一个按钮被点击时,它会触发:
(void) shareButtonTapped:(UIControl *)button withEvent:(UIEvent *) event
{
NSIndexPath * indexPath = [self.tableview indexPathForRowAtPoint:[[[event touchesForView: button] anyObject] locationInView: self.tableview]];
if ( indexPath == nil )
return;
[self.tableview.delegate tableView:self.tableview accessoryButtonTappedForRowWithIndexPath:indexPath];
}
或
(IBAction)callButtonTapped:(UIControl *)button withEvent:(UIEvent *)event {
NSIndexPath * indexPath = [self.tableview indexPathForRowAtPoint:[[[event touchesForView: button] anyObject] locationInView: self.tableview]];
if ( indexPath == nil )
return;
[self.tableview.delegate tableView:self.tableview accessoryButtonTappedForRowWithIndexPath:indexPath];
}
然后我使用下面的方法来处理触摸事件。
(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Accessory tapped for row %d", indexPath.row);
}
我的问题:在“accessoryButtonTappedForRowWithIndexPath”中,如何确定 UITableViewCell 中按下了两个按钮中的哪一个?我想以不同的方式处理每一次触摸。
【问题讨论】:
-
你为什么最终调用accessoryButtonTappedForRowWithIndexPath,为什么不调用你的自定义方法?
-
我认为这是最佳实践......假设这就是按钮应该在 UITableViewCells 中处理的方式。我在这里不正确吗?我需要按下按钮的索引以及按下的按钮类型
-
据我所知,由于您没有使用辅助按钮,因此不需要调用此方法。您可以实现自己的事件处理方法。
-
如果它显示在每一行(即每个UITableViewCell)上,它不会被认为是一个附属按钮吗?我会尝试调用我自己的方法
-
不,这不是辅助按钮,辅助按钮是当您设置 tableViewCell 的 accessoryType 属性并且您永远不能在同一个单元格上拥有 2 个时。
标签: ios uitableview