Search code examples
iosswiftuitabbar

Swift tabBar doesnt refresh view when navigated to


So im new to the Swift and Xcode world.

The expected usage:

  • The app has an tabBar with 3 tabs.
  • I go to the tab "search" and i click a row in a tableView, this writes an Int to a userDefault
  • I now click on the home tab that reloads and reads that userDefault and gets data from an api again like the first start of the app

The problem:

  • When i start the app it gets the key from userDefaults and read the data but when i then go to the search tab and change the userDefaults and click the home tab again its just going back on the backstack so no reload.

Ive searched and searched and only found weird solutions with notifications and stuff...

How do i call like the code below that reloads a fragment in android in Swift?

FragmantClass rSum = new FragmantClass(); getSupportFragmentManager().beginTransaction().remove(rSum).commit();

Yes i want the whole viewDidLoad() to run again...


Solution

  • The view controllers are not being recreated, so viewDidLoad will not run again. Look at viewWillAppear instead.