【问题标题】:Determine the sender from Multiple Accessory Buttons in a UITableViewCell?从 UITableViewCell 中的多个附件按钮确定发件人?
【发布时间】: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


【解决方案1】:

正如 Mariam 所指出的,我使用自己的自定义方法来接收呼叫,而不是内置的 accessoryBUttonTappedForRowWithIndexPath 方法。

【讨论】:

    猜你喜欢
    • 2018-10-01
    • 2010-11-10
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 2011-12-17
    相关资源
    最近更新 更多