简体   繁体   中英

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)")
        }
    }
}

I have multiple sections in table view. In sections, i have two textfield and some (Radio)Buttons.I have Submit Button in last cell.I want to get data on submit button @IBAction from textfields and selected buttons.

The most common way of doing this is by collecting the data whenever a textfield ends editing. Delegate method for UITextFieldDelegate textFieldDidEndEditing.

You can track the UIButton action from its position like below:

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)

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM