我是swift新手,当我点击viewForFooterInSection中的按钮时会遇到问题
我的代码是这样的
在viewForFooterInSection中
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerview = Bundle.main.loadNibNamed("TimeSheetFooterTableViewCell", owner: self, options: nil)?.first as! TimeSheetFooterTableViewCell
let dictFeeStats = arrFinancialYears[section] as? [String:Any]
footerview.lblTimeSheetFooterID.text = dictFeeStats?["staff_timesheet_id"] as? String
footerview.btnAccept.tag = section
footerview.btnAccept.addTarget(self, action: #selector(btnAcceptClick), for: .touchUpInside)
return footerview
}单击按钮时
@objc func btnAcceptClick(_ sender: UIButton)
{
let index = IndexPath(row: sender.tag, section: 0)
let cell: TimeSheetFooterTableViewCell = self.tblview.cellForRow(at: index) as! TimeSheetFooterTableViewCell
let comment = cell.lblTimeSheetFooterID.text
print("buttonPressed ! \(sender.tag)")
}如何在注释变量中获取TimeSheetFooterTableViewCell值。提前感谢!
发布于 2020-08-16 23:17:29
您可以在TimeSheetFooterTableViewCell中添加一个接受字符串的闭包。当点击按钮时,使用文本视图的文本调用该闭包。
var acceptButtonTapped: ((String?) -> ())?
@IBAction func btnAcceptClick(_ sender: UIButton) {
acceptButtonTapped?(txtview.text)
}在tableView(_ tableView: UITableView, viewForFooterInSection中,从回调中获取文本。
footerview.acceptButtonTapped = { text in
print(text)
}https://stackoverflow.com/questions/63438315
复制相似问题