我有一个tableviewcontroller
,我在 .xib 文件中创建了自定义 tableviewcell。
myCustomTableViewCell.xib 上使用的按钮 (myButton) 有一个到 myCustomTableViewCell.swift 的出口
我在 TableViewController.swift 文件中为按钮设置了一个动作
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("myCustomTableViewCell", owner: self, options: nil)?.first as! myCustomTableViewCell
cell.myButton.setTitle(arrayOfMyData[indexPath.row].myText, for:.normal )
//other code to set some other cell.attribute values like above (all works)
cell.myButton.actions(forTarget: "myAction", forControlEvent: .touchUpInside)
}
在 TableViewController.swift 的其他地方我有这个动作:
func myAction(sender: UIButton){
print("pressed myButton")
}
但 myAction 从未被调用/“pressed myButton”从未被打印。我错过了什么?