0

I want to pass data from a view controller to tabbar controller, and then from this tab bar controller to its view controller with using their class. I succeeded to transfer from view controller to tabbar controller using segue. However, I cannot transfer data from tabbar controller to its one of the view controller.

Any idea/documentation will be appreciated. Here is the screenshot about what I want to do from xcode screenshot-xcode

2 Answers 2

2

Take a look at the documentation for the tab bar controller, in particular the viewControllers property.

That property is an array of UIViewControllers, in the order they appear in the tab bar, so you can pick the one you need (viewControllers[0] from your screen shot), cast it to your specific view controller subclass and then pass it your data.

Sign up to request clarification or add additional context in comments.

Comments

2

At last, I am able to solve the issue, many thanks to the answer. Here is the detailed explanation for beginners like me:

This is the source controller class, which is a tabbar controller and it transfers the data:

class SourceTC: UITabBarController { var dataTransferFrom = "transfer this string" override func viewDidLoad() { super.viewDidLoad() let finalVC = self.viewControllers![0] as! DestinationVC //first view controller in the tabbar finalVC.dataTransferTo = dataTransferFrom } } 

and this is the destination controller class, which is a view controller under tabbar controller and it gets the transferred data:

class DestinationVC: UIViewController { var dataTransferTo = "" override func viewDidLoad() { super.viewDidLoad() print(dataTransferTo) } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.