简体   繁体   English

自定义单元中的UIButton无法正常工作

[英]UIButton in custom cell not working

I have a button in a custom cell 我在自定义cell有一个button

class CardTableViewCell: UITableViewCell {
    @IBOutlet weak var detailsButton: UIButton!
}

in my view controller then I do this 在我的view controller然后执行此操作

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    //.....more code....
    openDealCell.detailsButton.addTarget(self, action: "push:", forControlEvents: UIControlEvents.TouchUpInside)      
}

and then: 然后:

func push(sender:AnyObject) {
    println("tap")
}

But when I clicked the button nothing happens. 但是,当我单击button什么也没有发生。

What I am doing wrong? 我做错了什么?

Fix it! 修理它! The problem was not in the code but in my cell in the storyboard: 问题不在于代码,而在于故事板中的单元格:

在此处输入图片说明

where user interaction for the cell wasn't enabled and all the other view didn't allow the user interaction. 其中未启用该单元的用户交互,而所有其他视图均不允许该用户交互。

在此处输入图片说明

Right now I created demo project with exactly the same code as your and it works. 现在,我使用与您的代码完全相同的代码创建了演示项目,并且它可以正常工作。 Please check here at GitHub. 请检查在这里在GitHub上。 The issue definitely in the other stuff that you didn't show us, that code does not have any problems 您未向我们展示的其他内容中肯定存在该问题,该代码没有任何问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM