swiftuitabbarcontrolleruitabbaruistoryboardsegueunwind-segue

Come back to the tabBarController, swift



Currently on my viewController : Upload, my button send the data to my database only if all the information are filled out, and I come back to the preview view (table View) with :
self.navigationController?.popViewControllerAnimated(true)

I would like, if it is possible, to come back to my main view on the tabBarController. I tried many things, like directly on the storyboard with Present modally segue to "TabBar controller", but I come back to the TabBar without sending my data to the database and without checking in the information are filled out..

How can I do it?

Thanks!


Solution

  • UITabBarController has a property selectedIndex with which you can switch the selected tab. So on completion after dismissing the UploadViewController you can run:

    self.tabBarController?.selectedIndex = 0 // Index to select
    

    It would probably be best to create a delegate for your UploadViewController to fire a function to do all the work in your previewVC on API call completion.