如何在@ibaction按钮中获取数据的数据委员会方法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)")
        }
    }
}

我在表观中有多个部分。在节中,我有两个Textfield和一些(Radio)按钮。

最常见的方法是每当文本字段结束编辑时收集数据。uitextfielddelegate textfielddeddendediting的委托法。

您可以从其位置跟踪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)
    }

最新更新