Asked 8 years ago
28 Oct 2016
Views 1275
QuickIos

QuickIos posted

How can i get navigation from the tab UIViewController to UITabBarController


class EditProfileTabController: UITabBarController, UITabBarControllerDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
         self.delegate = self
        
         
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
 
       let prefiledetail = ProfileViewController()
         
        let tabOneBarItem = UITabBarItem(title: "Profile", image:  UIImage() , selectedImage:   UIImage() )
        // Create Tab  Review
       let tabTwo = ReViewController( )
        let tabTwoBarItem2 = UITabBarItem(title: "Reviews", image:   UIImage() , selectedImage:  UIImage())
          
        self.viewControllers = [tabOne, tabTwo]
    
    }
    
}

i am loosing navigation item for both of UIViewController at tabBar
jaydeep

jaydeep
answered Apr 24 '23 00:00

To transition from a UIViewController that has a navigation bar to a UITabBarController , you can take the following steps:

1. Create a new instance of UITabBarController .
2. Set the view controllers that you want to display in the tabs on the UITabBarController by adding them to an array.
3. Make the UITabBarController the root view controller of the navigation controller or the window.
The following code provides an example of how this can be done:



// Create a new instance of the tab bar controller and specify its view controllers
let tabBarController = UITabBarController()
let firstViewController = FirstViewController()
let secondViewController = SecondViewController()
tabBarController.viewControllers = [firstViewController, secondViewController]

// Set the tab bar controller as the root view controller of the window or the navigation controller
if let navigationController = self.navigationController {
    navigationController.setViewControllers([tabBarController], animated: true)
} else {
    self.view.window?.rootViewController = tabBarController
}

This code creates a UITabBarController instance and assigns the FirstViewController and SecondViewController as the view controllers that will appear in the tabs. Then, depending on whether there is a navigation controller or not, it sets the UITabBarController as the root view controller. If there is a navigation controller, it sets the UITabBarController as the root view controller of the navigation controller using the setViewControllers(_:animated:) method. If there is no navigation controller, it sets the UITabBarController as the root view controller of the window using the rootViewController property.

It is worth noting that if you want to keep the navigation stack of the UIViewController, you can embed the UIViewController in a UINavigationController, and then set the UITabBarController as the root view controller of the UINavigationController. This way, the navigation stack of the UIViewController will be preserved when transitioning to the UITabBarController.
pratik

pratik
answered Apr 27 '23 00:00

Cimb

Cimb
answered Apr 27 '23 00:00

shabi

shabi
answered Apr 27 '23 00:00

jessica

jessica
answered Apr 27 '23 00:00

Post Answer