我无法理解为什么addTarget
我UIButton
的 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
并且效果很好。
万分感谢!