非常抱歉我的英语不好,如果我说错了什么,请见谅。这是我在这里提出的第一个问题。
我有一个自定义的UITableViewCell作为*.xib文件中的视图,其中包含了一个UIImage和一个在该UIImage上的按钮。 我将此按钮与我的CustomTableViewCell.swift类中的outlet连接了起来。
@IBOutlet weak var authorImage: UIImageView!
@IBOutlet weak var authorButton: UIButton!
在MyTableViewController.swift中,我已经注册了一个nib。
tableView.registerNib(UINib(nibName: "CustomTableViewCell", bundle: nil), forCellReuseIdentifier: "my_cell")
我编写了一个类似这样的 cellForRow... 函数:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("my_cell", forIndexPath: indexPath) as! CustomTableViewCell
cell.authorButton.addTarget(self, action: "authorButtonPressed:", forControlEvents: .TouchUpInside)
return cell
}
最后,我有这个函数(我在addTarget中使用):
func authorButtonPressed (sender:UIButton!) {
print("Hi!")//line1
print(sender)
}
在第一行设置断点,但这个函数从未被调用。
当我点击按钮时,我也意识到它没有动画效果。
我该如何修复它或找到解决方案?
提前感谢您。