Search code examples
iosswiftuinavigationcontrolleruitabbarcontroller

Navigate between Screens


In my application,I have complex navigation.

I have Shopping Details .Which is View Controller of Tab bar controller.

When I select the any Store Name from Shopping Details View Controller .It will pop to a Shopping List View Controller which is embed in Navigation Controller.

When Select the Edit Button from Shopping List View Controller .It will pop to another View controller which ADD Screen. It is also embed in Navigation Controller

When I click save from Add Screen .It will go to the Shopping List View Controller

When I click Done button from the Shopping List View Controller .I have to navigate to Shopping Details View Controller of Tab bar controller.

Please provide me input. How to traverse to Tab Bar Controller ?

I have tried below Code. It is navigate to StoreDetails View Controller.Not displaying Tab Bar Items

let storeDetails = self.storyboard?.instantiateViewController(withIdentifier: "StoreDetailsController") as! StoreDetailsController
        storeDetails.managedContext = managedContext
        storeDetails.coreData = coreData
        storeDetails.back = true
self.navigationController?.pushViewController(storeDetails, animated: false)

Solution

  • Since it is interconnected . pushToViewController or popTOViewController or dismiss is not worked. so I have used unwind.

    StoreDetailsController: I have below code in StoreDetailsController

    @IBAction func unwindToVC1(segue:UIStoryboardSegue) {
            print("Test")
        }
    

    In my ShoppingListViewController I have unwind Done bar button to exit.

     @IBAction func done(_ sender: UIBarButtonItem) {
    performSegue(withIdentifier: "unwindSegueToVC1", sender: self)
           }
    

    you can follow the below link for unwind

    https://medium.com/@mimicatcodes/create-unwind-segues-in-swift-3-8793f7d23c6f