我有这个问题,希望你能帮助我。
这是我的代码viewForHeaderInSection
:
let button = UIButton(frame: CGRect(x: view.frame.width - (cancel.frame.width + xImage.frame.width + 100), y: view.frame.origin.y, width: cancel.frame.width + xImage.frame.width + 120, height: view.frame.height))
button.backgroundColor = UIColor.blue.withAlphaComponent(0.5)
button.addTarget(self, action: #selector(action), for: .touchUpInside)
view.addSubview(button)
这是 action
功能:
@objc func action(sender: UIButton) {
let position: CGPoint = sender.convert(CGPoint.zero, to: self.tableView)
if let indexPath = self.tableView.indexPathForRow(at: position) {
let section = indexPath.section
print(section)
}
}
现在,如果我点击除第一个标题(标题 0)以外的每个标题,它会打印正确的部分。如何让它也检测到标头 0?