accessoryButtonTappedForRowWithIndexPath不适用于自定义按钮或标签

时间:2016-03-08 12:21:41

标签: ios swift uitableview uiaccessoryview

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
      let key =  keyArray[indexPath.section-1]
      let label = UILabel(frame: CGRectMake(0, 0, 26, 28))
      label.center = CGPointMake(26, 28)
      cell.accessoryView = label
}

    override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
        print(indexPath)
    }

为什么自定义标签或自定义按钮不会调用accessoryButtonTappedForRowWithIndexPath。或者只有一种方法将myButton添加到单元格中?

1 个答案:

答案 0 :(得分:7)

对于自定义按钮,您可以为特定事件添加目标,accessoryButtonTappedForRowWithIndexPath不适用于自定义视图

请参阅:

enter image description here