Ios 自定义单元格中的UIButton不工作
我在自定义的Ios 自定义单元格中的UIButton不工作,ios,swift,uibutton,custom-cell,Ios,Swift,Uibutton,Custom Cell,我在自定义的单元格中有一个按钮 class CardTableViewCell: UITableViewCell { @IBOutlet weak var detailsButton: UIButton! } 在我的视图控制器中执行此操作 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { //.....more
单元格中有一个按钮
class CardTableViewCell: UITableViewCell {
@IBOutlet weak var detailsButton: UIButton!
}
在我的视图控制器中
执行此操作
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//.....more code....
openDealCell.detailsButton.addTarget(self, action: "push:", forControlEvents: UIControlEvents.TouchUpInside)
}
然后:
func push(sender:AnyObject) {
println("tap")
}
但是当我点击按钮时,什么也没发生
我做错了什么?现在,我创建了一个演示项目,使用了与您的完全相同的代码,它可以正常工作。请在GitHub查询。在您没有向我们展示的其他内容中,该问题肯定存在,该代码没有任何问题修复它!问题不在代码中,而是在故事板中的我的单元格中:
未启用单元格的用户交互,并且所有其他视图都不允许用户交互
检查详细信息按钮可能未链接到界面生成器中的UITableViewCell。打印cellForRowAtIndexPath委托方法中的detailsButton并检查对象是否存在?@Shashi3456643当我打印按钮时,我得到了
是的代码看起来很好。能否尝试在interface builder中链接func push(发送方:AnyObject)方法并从中删除addTargetcellForRowAtIndexPath@Shashi3456643有没有可能是因为按钮在其他视图的后面?不,您的代码看起来很好,您的方法是正确的。我只是告诉你另一种方法来让它工作。