处理uibutton点击uitableview导致错误

时间:2015-08-14 05:21:37

标签: ios swift uitableview uibutton

我有一个包含按钮的UITableViewCell,我处理此按钮点击事件请点击此链接Get button click inside UI table view cell

这是我的代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            cell.directCommentButton.tag = indexPath.row;

    cell.directCommentButton.addTarget(self, action: "directCommentButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
    return cell
}

func directCommentButtonClicked(sender: AnyObject) {
    // directComment = 1
    println("DIRECT COMMENT")
}

但是错误directCommentButtonClicked]: unrecognized selector sent to instance 0x7f9e50590f10'并且应用已崩溃。当我删除发件人:AnyObject时,错误消失了,但我想得到发件人,我该怎么做。事先提前

1 个答案:

答案 0 :(得分:3)

以这种方式传递你的动作选择器:

cell.directCommentButton.addTarget(self, action: "directCommentButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)

你必须添加:,因为你的函数接受了一个参数。