【发布时间】:2015-10-26 20:31:05
【问题描述】:
我真的很抱歉我的英语,如果我做错了什么,这是我在这里的第一个问题。
我有一个自定义 UITableViewCell 作为 *.xib 文件中的视图。里面有一个 UIImage 和那个 UIImage 上的一个按钮。 我将此按钮与插座连接到我的 CustomTableViewCell.swift 类。
@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)
}
和第一行的断点。但是这个函数永远不会被调用。
而且我也刚刚了解到,当我点击它时,该按钮没有动画。
我该如何解决它或找到解决方法?
提前谢谢你
【问题讨论】:
-
您 100% 确定按钮位于图像顶部而不是其后面?如果您暂时删除/隐藏图像,问题是否仍然存在?
-
@j.f.我刚刚删除了按钮周围的所有内容。但是当我点击它时它仍然没有改变。并且 authorButtonPressed: 函数不会开始执行。我还尝试使用视图层次结构调试器来查看是否有东西可以在我的按钮上,但按钮上唯一的东西是 UITableViewCellContentView。这是图片:dropbox.com/s/qb08tm08l5i0i9a/…
-
你能贴一张你的xib的截图(带有文档大纲)吗?
-
@joern 我已经完全删除了单元格上的所有内容,但我的按钮 dropbox.com/s/be8p26d7hbqy1qs/…
标签: ios swift uitableview uibutton