Reload tableView after dismiss a viewController

前端 未结 5 1053
遇见更好的自我
遇见更好的自我 2021-02-14 14:05

I have a ViewController(VCA) with a TableView inside. From this ViewController it is possibile to call another ViewController (VCB). In this second VC it is possibile add an ite

5条回答
  •  没有蜡笔的小新
    2021-02-14 14:47

    you can do this in two way :-

    1)
    Do One thing in VCA

    VCA

       override func viewWillAppear(_ animated: Bool){
           tableView.reloadData()
       }
    

    If this does not work out then try this.

    2) create an instance of VCA in VCB and whenever you move from VCA to VCB pass the value of VCA to the instance of VCB and from there reload the table.

    VCB

        var instanceOfVCA:VCA!    // Create an instance of VCA in VCB
    
       func saveButton(){
        instanceOfVCA.tableView.reloadData()  // reload the table of VCA from the instance
        dismiss(animated: true, completion: nil) 
      }
    

    VCA

     override func prepare(for segue: UIStoryboardSegue, sender: Any!) {
      VCB.instanceOfVCA = self   // Pass the value of VCA in instance of VCB while navigating through segue
    }
    

提交回复
热议问题