0

I have 3 viewControllers:

VcA: I read data with observers from database and pass with segue to VcB.

VcB: I read data and display it, with a button I call VcC to update data passing datas with segue.

VcC: a STATIC tableview in wich I update data and save them.

The problem is that when I dismiss after saved VcC and go back in VcB all data is old, even if in firebase all datas are perfectly updated.

In VcB for example I read the Title like this:

 var groupName: String?

than in didAppear:

 Name.title = groupName

Anyway if I also go back from VcB to VcC all data of the table are the old data.

To be more clear:

I call the database in VcA

enter image description here

click the name in the table and pass the data to Vcb, all is fine for now, title and other vars are ok

enter image description here

now I click EDIT and call to VcC, the table where I update the data, make change and save,

enter image description here

after save VcC dismiss and I go back to VcB -> title is still p2 but in firebase not!

enter image description here

I click again on EDIT to return to VcC (the edit table), title is the old one

enter image description here

I think that I have to recall datas from db... anyway to do it without refresh the data from firebase?

I know that if I go back to VcA after save all is fine but I really need to go to VcB, how can I do?

I found many threads, this is the most similar but not exact situation... Reload tableView after dismiss a viewController

Jay
  • 610
  • 3
  • 16
HaVaNa7
  • 310
  • 1
  • 3
  • 13

1 Answers1

0

If I can follow this correctly.

VcC:

protocol %NAME%Delegate
{
    func reloadData()
}


class VcC: UIViewController /*(or table)*/{
    var mDelegate : %NAME%Delegate?


    //in the func you use to dismiss self (VcC)
    //mDelegate?. reloadData()

}

VcB:

class VcB: UIViewController /* (or table)*/,%NAME%Delegate  {
    func reloadData(){
       tableView.reloadData()
       //OR
       //Observer for Firebase here to gather the new information. Make sure to reset all datasources if you do this.
    }
}
Torewin
  • 743
  • 7
  • 20
  • thnx but in VcB I have a simple ViewController not a table, the table is in VcC only – HaVaNa7 Oct 16 '17 at 07:52
  • It’ll work regardless. I just didn’t know which class to add. It’ll work with ‘view’ and ‘table’. – Torewin Oct 16 '17 at 12:01
  • I did it but when I arrive at VcB the title is still the old one maybe a problem with my dismiss method? _ = navigationController?.popViewController(animated: true) – HaVaNa7 Oct 16 '17 at 13:04
  • Make sure you're calling `mDelegate?.reloadData()` before the dismiss method. https://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them Here is a perfect example of what you are trying to accomplish. Very detailed answer. – Torewin Oct 16 '17 at 15:19