UITutViewCell里面的UIButton没有接收到水龙头?

时间:2018-02-12 03:03:58

标签: ios uitableview uibutton

我在表格视图中有这个书签按钮: enter image description here enter image description here

由于某种原因,它没有回应接触。我有一个简单的IBOutlet,其中包含一个永远不会调用的print语句。但是,当我点击书签时,单元格不会像单击它那样动作。但是,当我点击书签时,单元格不会像单击它那样动作。因此,在我看来,系统知道按钮应该接收按钮(而不是单元),但IBOutlet不起作用。有任何想法吗?为按钮及其超级视图启用了用户交互。

1 个答案:

答案 0 :(得分:0)

将目标添加到 cellForRowAtIndexPath()方法中的书签按钮,并执行点击书签按钮时要执行的操作  例如:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cellReuseIdentifier")
    cell.Bookmark.addTarget(self, action: #selector(tapBookMark(_:)), for: .touchUpInside)
    return cell
}


func tapBookMark(_ sender: UIButton) {
     print('bookMark tapped')
}
相关问题