I have a Tab Controller, other controllers are connected to it in a storyboard.

For example: there is a Table View Controller controller, it is connected as a separate tab. For this controller, I created a class in which I redefined methods.

I have at least three tabs of the same type, and it would be more rational for me to use one class for them, but just to set the desired mode in this class in a certain variable.

In accordance with this regime, the class will behave in its own way. The essence is different.

Question: How to make it so that when switching tabs to the class passed the necessary data?

Those. I will have 3 tabs, one for the news feed, the other for the personal posts feed, and the third for the best posts.

And each of the tabs will have the same class, but when the user clicks on the button of one of the tabs, then when opening it is necessary to somehow transfer this role to this class.

If you do not use the Tab Controller, and for example open this screen with a button, then I can set the segue and in the prepareForSegue set the desired value for the variable. But with the tabs I do not know how to be.

I hope clearly explained))

    1 answer 1

    As an option, add a tag to each tab bar item. Then it will be possible to determine which tab to use:

    override func viewWillAppear(_ animated: Bool) { let usedTabBar = self.tabBarController?.tabBar.selectedItem?.tag 
    • Thanks, I'll try a little later. Then I will say how it helped. - cheerful_weasel
    • Created a new project for the test. Everything is working. Thank you for help! - cheerful_weasel