2

我无法理解为什么addTargetUIButton的 in 在特定情况下不起作用。

因此,有一个UITableViewCell我以编程方式创建按钮的地方,例如:

let myClickButton : UIButton = {
    let button = UIButton()
    button.setTitle("Hit Test", for: .normal)
    button.tintColor = UIColor.white
    button.addTarget(self, action: #selector(printMessage), for: .touchUpInside)
    button.isUserInteractionEnabled = true
    return button
}()

而且,我的UITableViewCell班级中还有一个按钮应该调用的函数:

func printMessage(){
    print("button was clicked")
}

但是,该printMessage函数永远不会被调用,并且控制台中没有错误。你能帮我理解这个案子有什么问题吗?这似乎是一个问题,UITableViewCell因为我确实定期对其进行了测试,viewController并且效果很好。

万分感谢!

4

1 回答 1

2

根据按钮的关闭位置,我会在 UITableViewCell 被实例化后尝试设置目标。除此之外,如果没有看到更多代码,我不确定问题出在哪里。

于 2017-07-28T23:02:10.437 回答