【发布时间】:2017-12-14 06:14:35
【问题描述】:
我正在通过 viewForFooterInSection 的委托方法在我的 TableView 控制器中添加一个静态页脚视图,它工作正常,它正在添加我所需的设计,就像我想要的那样,但在按钮上的 touchUpInside 上没有调用操作。我已经通过堆栈并尝试了几乎所有方法都无济于事。我可能做错了什么。这是我的代码
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = UIColor.white
let blackView = UIView()
blackView.frame = CGRect(x: 0, y: 51, width: self.view.frame.size.width, height: 2)
blackView.backgroundColor = UIColor.black
view.addSubview(blackView)
let button = UIButton()
button.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 51)
button.titleLabel?.font = UIFont.init(name: "Lato-Bold", size: 22)
button.titleLabel?.textColor = UIColor.black
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
view.addSubview(button)
return view
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 53
}
@objc func buttonAction(sender: UIButton!) {
print("Button tapped")
}
【问题讨论】:
-
我刚刚在 Playground 上对其进行了测试,它工作正常我在控制台中获得了 Button Tapped
标签: ios swift uitableview uibutton