How to pass data between view controller and the tab-bar's view controllers using segue?

How to pass data between view controller and the tab-bar's view controllers using segue?

pass data from tab bar controller to view controller
pass data between view controllers swift without segue
passing data between view controllers (swift programmatically)
how to pass data from second view controller to first view controller in swift
swiftui pass data between views
pass data to child view controller swift
pass data to controller swift
how to pass data from viewcontroller to tableviewcontroller

enter image description here

I aslo added the screenshot of the design.

I'm having a one viewcontrollerA and a tabbar with 2 view controller B,C.

I want to pass the data of data variable from VcA -> VcB via tabbar.

I have dragged the segue from submitbutton to the TabBar.

I tried to pass the data with segue

So, please help me out from this.

//In  View controller A
class ViewControllerA : UIViewController{
var data : String = ""
    @IBAction func submitButtonTapped(_ sender: Any) {   
    performSegue(withIdentifier: "homePage", sender: nil)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let vc = self.tabBarController!.viewControllers![0] as! ViewControllerB

     vc.containsData = data

    }

}
//In Tabbar View controller B
class ViewControllerB: UIViewController {
    var containsData : String = ""
    override func viewDidLoad() {
        super.viewDidLoad()
    print(containsData)

    }
}

In Tab bar's viewcontrollerB I just printed the var "data" in viewDidLoad()


Looking in to the code, i figured out the issues.

First you need to use prepare(for segue method to pass data as your are presenting viewControllerb using segue. So, in your ViewController, add this method and set data for ViewControllerb as below,

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if let tabController = segue.destination as? UITabBarController {
        let bController = tabController.children.first(where: { $0 is ViewControllerb })
        (bController as? ViewControllerb)?.containsData = self.stringTF.text!
    }
    super.prepare(for: segue, sender: sender)
}

Second, remove method submitButtonTapped from ViewController because you are presenting ViewControllerb using segue so this is not required. Also remove this method outlet in the storyboard by clicking cross as shown in the below image

Passing data between tab viewed controllers in swift?, If you need to pass the data between view controllers then : var secondTab = self.​tabBarController?.viewControllers[1] as  Passing data between view controllers inside a tab bar controller. Another common container in iOS apps is the tab bar controller. This allows the user to switch between different tabs using a tab bar at the bottom of the screen. Sometimes, you need to update one tab as a consequence of a user action in another tab.


I got my answer

    @IBAction func submitButonTapped(_ sender: Any) {
            performSegue(withIdentifier: "homePage", sender: self)
    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let barViewControllers = segue.destination as! UITabBarController
        let destinationViewController = barViewControllers.viewControllers![0] as! ViewControllerB
        destinationViewController.containsData = Data
    }

How to pass data through TabBarCon…, How to pass data through TabBarController? Hi everyone,. I try to pass data from View Controller through Tab Bar Controller and Navigation Controller to Table  Currently how I have it; when the user press the "Load Button" on MainViewController when the application first starts, it loads the first (top) view controller (Table View) on Tab Bar Controller but not the other items. When the user press the second Tab Bar item, then it load the data for that Table View Controller. Typical case, no issue.


If you are pass data viewController -> Tabcontroller using NavigationController. please try blow code on button/ tableviewCell/ collectionViewCell Click/ Press


let navController = self.Your_TABBAR_CONTROLLER.viewControllers![Tab_Index] as! UINavigationController
let vc = navController.topViewController as! Your_View_Controller
vc.name = Data

let navController = self.tabBarController.viewControllers![1] as! UINavigationController
let vc = navController.topViewController as! HomeViewController
vc.name= self.name

Swift Swift Tutorials: Passing Data in Tab Bar Controllers – Make , Updated for Swift 2.0/iOS9 9/21/15 SJL] While you can delegate between view controllers in tab bar controllers, it's debatable if you want to. In the drop-down menu, select Editor>Embed in>Tab Bar Controller. In Update Frames, select Items of new constraints. Select Items of New Constraints for Update Frames. Click on the view controller icon for the Pizza view, and in the identity inspector, change the view controller to PizzaViewController.


Passing Data Between View Controllers in iOS: The Definitive Guide, In iOS apps, a tab bar controller is usually the initial view controller, which is reachable from the app delegate. Let's start by creating a model  Passing Data Between View Controllers Using Segues (A → B) If you’re using Storyboards, you can pass data between view controllers with segues, using the prepare(for:sender:) function. Passing data between view controllers, using Storyboards, isn’t that much different from using XIBs. Let’s find out how to pass data forward using segues.


Swift4: Sharing Data Model across Views in Tab Bar Controller , Pass data between tab bar view controllers programmatically. Unfortunately, didSelectViewController is only called when a user physically taps  Pass Data Between Controller and View. In the above image, you can see how data flows from the "Controller" to the "View", and how it looks in the browser. Pass Data Between View to View. In the above image, you see how data is initialized on the "View" page itself using 'ViewBag.Title = "Index"' and then how it is getting rendered using


Pass data between tab bar view controllers programmatically , How do you handle moving back from a navigation controller? How do you pass data between view controllers? How do you use tab bar  View Controller to Tab Bar Controller - Passing Data I have a login view controller, if the user input a correct information the next controller will be a tab bar controller. My problem is how can I pass data between view controller to tab bar controller.