里面一个UITableViewCell
,我正在尝试实现一个button与两个image and a text.
看来是标准UIButton
无法实现这一点。所以我创建了一个UIView
其中包含一个UIImageView
and a UILabel
.
您可以在右侧看到实现,“follow trip”按钮(“+”是 UIImageView,“follow trip”是 UILabel)
我现在正在尝试做这样的UIView
(即按钮)可点击,但我找不到办法。
这是我的实现,但它不起作用:
class StationsIntroHeader: UITableViewCell {
@IBOutlet weak var bigButton: UIView!
override func awakeFromNib() {
super.awakeFromNib()
let tap = UITapGestureRecognizer(target: self, action: Selector("followTrip:"))
bigButton.addGestureRecognizer(tap)
}
func followTrip(sender:UITapGestureRecognizer) {
print("tap working")
}
}
我已经确定了启用用户交互为 ON 上UIView
和关闭两个UIImageView
and UILabel
对我来说,像下面这样的示例设置完全有效:
class TableViewController: UITableViewController {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath)
}
}
class CustomCell: UITableViewCell {
@IBOutlet weak var bigButton: UIView!
override func awakeFromNib() {
super.awakeFromNib()
let tap = UITapGestureRecognizer(target: self, action: Selector("bigButtonTapped:"))
bigButton.addGestureRecognizer(tap)
}
func bigButtonTapped(sender: UITapGestureRecognizer) {
print("bigButtonTapped")
}
}
我没有更改任何默认值userInteractionEnabled
用于视图或图像视图或标签。将我的实现与您的实现进行比较,看看您是否忘记了某些内容...例如,您是否忘记了某些内容?连接插座?
示例项目:https://www.dropbox.com/sh/hpetivhc3gfrapf/AAAf6aJ0zhvRINPFJHD-iMvya?dl=0 https://www.dropbox.com/sh/hpetivhc3gfrapf/AAAf6aJ0zhvRINPFJHD-iMvya?dl=0
为您的项目进行编辑
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("StationsIntroHeader") as! StationsIntroHeader
headerCell.update()
return headerCell
// return headerCell.update().contentView
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)