Felix Felix - 1 year ago 77
Swift Question

Tab bar; childView segues

I'm trying to make an app which has a Tab bar View with 2 Views. The first contains a tableView. With the second you can add Elements to the tableView. Now I want to be able to communicate between the to Views

Are there segues when you switch tabs in the tab bar controller? How can I intercept them? If not, are there any other possibilities to communicate between the two Views?

Answer Source

You can intercept the actual switch between view controllers by using UITabBarControllerDelegate with the method tabBarController:didSelectViewController::

Tells the delegate that the user selected an item in the tab bar.

There is a neat implementation you can do by going to the object library and search for "object":

enter image description here

Drag it to your Tab bar view controller and set it's delegate by ctrl + drag.

Choose it:

enter image description here

and set a custom class in the inspector:

enter image description here

When you right click the Object you should see:

enter image description here

Here is an example of your CustomClass:

class CustomClass : NSObject, UITabBarControllerDelegate
   func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController)

While the viewController param is:

The view controller that the user selected. In iOS v3.0 and later, this could be the same view controller that was already selected.

Which means you need to check which VC is it.