我在表button
中有一个header view
,需要执行该操作才能确定按下哪个section
按钮(哪个标题)
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
let view = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 28))
let button = UIButton(type: UIButtonType.system)
button.setTitle("+", for: UIControlState.normal)
button.addTarget(self, action: #selector(GLAccountTableViewController.buttonTouched), for: UIControlEvents.touchUpInside)
view.addSubview(button)
return view
}
有没有办法识别按下哪个部分的按钮?
最佳答案
如果我对您的理解正确,则需要某种方式来触发按钮,然后单击headerView。
您可以在创建按钮时参考该部分添加标签
button.tag = section
然后,在onclick函数中,您知道在哪个部分中按下了按钮。