[英]how to get data in @IBAction button for cell for row delegate method tableview swift 3
var textfield_name:String?
@IBAction func Btn_submit(_ sender: Any){
let position: CGPoint = (sender as AnyObject).convert(CGPoint.zero, to: table_view)
if let indexPath = table_view.indexPathForRow(at: position){
let Section_count = table_view.numberOfSections
let rowsCount = table_view.numberOfRows(inSection: 0)
for i in 0..<rowsCount{
// let index = IndexPath(row: i, section: 0)
let cell = table_view.cellForRow(at: indexPath) as! UITableViewCell
// let cell: UITableViewCell = table_view.cellForRow(at: index) as! UITableViewCell
textfield_name = cell.text_field.text!
print("cell is \(cell)")
}
}
}
我在表格视图中有多个部分。 在各节中,我有两个文本字段和一些(Radio)Buttons。我在最后一个单元格中有Submit Button。我想从文本字段和选定按钮中获取关于Submit Button @IBAction的数据。
最常见的方法是在文本字段结束编辑时收集数据。 UITextFieldDelegate textFieldDidEndEditing的委托方法。
您可以从如下位置跟踪UIButton
操作:
func getDataForButton(sender: UIButton!){
let buttonPosition = sender.convert(sender.bounds.origin, to: tblView)
let btnIndexPath = tblView.indexPathForRow(at: buttonPosition)
// reload the particular row if needed or fetch the data
tblView.reloadRows(at: [btnIndexPath!], with: .none)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.