getting data from each UITableView Cells Swift

后端 未结 3 1771
挽巷
挽巷 2020-12-03 09:23

I have searched the internet countless times and have not found a solution to my situation. Things that may be a solution are things I didn\'t understand and they were in Ob

3条回答
  •  再見小時候
    2020-12-03 09:48

    I know this is a very old post but then to if it helps someone I'll be happy so to do this the simple way which I will prefer is made an array of the UI table view cell and called it in the UI View Controller and then this becomes very simple just called the array (Thanks to rohan)

    (FOR EXAMPLE)

    import UIKit
    
    
    public class PlanningTableView:UITableViewCell{
    
        @IBOutlet weak var Sccode: UITextField!
        @IBOutlet weak var NoOfPatients: UITextField!
    
    }
    

    (AND NOW IN VIEW CONTROLLER DO THIS)

    import UIKit
    
    class PlanningReport:UIViewController,UITableViewDelegate,UITableViewDataSource{
    
        var ScCode = [String]()
        var NoOfPatient = [String]()
        var CollectionOfCell = [PlanningTableView]()
    
    
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PlanningTableView
        CollectionOfCell.append(cell)
        return cell
    }
    

    //////// Then at sumbmit Button just do this /////////////////

    @IBAction func Submit(_ sender: Any) {
    
         CollectionOfCell.forEach { cell in
               ScCode.append(cell.Sccode.text!)
               NoOfPatient.append(cell.NoOfPatients.text!)
         }
    }
    

    For more details I just created a YouTube first ever tutorial - comments good/bad appreciated

提交回复
热议问题