0

I am building an iOS app. this app has this structure:

tab bar item > box-view > navigation controller > table view
tab bar item > navigation controller > view

The first table view has a downPicker (an open source drop down menu). You can initialize a downPicker with an array to give him the elements to display.

Unfortunately, my second view, has an add button where you can add an element inside this downpicker.

The problem is, that if I open the table view, switch to the view, add an element, switch back to the table view (where the downpicker is located) those values do not get updated.

This problem does not appear if I go back to box-view after adding an element.

Currently the downPicker init is inside the viewWillLoad. So, is there a way to detect this switch between tabs and actually refresh the downPicker?

G. Ramistella
  • 1,327
  • 1
  • 9
  • 19
  • Possible duplicate of [Detect UITabBar Selected Index/ Item Changes that is set Programmatically](https://stackoverflow.com/questions/30692206/detect-uitabbar-selected-index-item-changes-that-is-set-programmatically) – Rakesha Shastri Oct 08 '18 at 18:43
  • @arturdev This is one of the basic things which you would not miss if you had gone through the apple docs for `UITabBarDelegate`. Please do a thorough research on the internet before asking trivial questions. Thanks! – GoGreen Oct 09 '18 at 11:18
  • Hmm dude why do you even bother replying to a solved question? – G. Ramistella Oct 09 '18 at 12:03

1 Answers1

3

Make a class that inherits from UITabBarController and override the following method:

//Swift
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
    //do your job here
}

//ObjC
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    //do your job here        
}

And set the class to your TabBarController from the storyboard.

arturdev
  • 10,884
  • 2
  • 39
  • 67