2


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!

L.Vl
  • 113
  • 2
  • 14

2 Answers2

1

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.

xoudini
  • 7,001
  • 5
  • 23
  • 37
0

(Super late response...in case someone has similar questions, presumably in later version of Swift, such as mine which is Swift 5, iOS 13.2). Steps:

  1. Be sure to set an id for your UITabBarController storyboard, e.g. "TabBarViewController"
  2. Next, add the following to an action that has already been connected to a button:

let ID_TABBAR = "TabBarViewCOntroller"

@IBAction func returnToTabbar(_ sender: Any) {
        let tabBarController = self.storyboard?.instantiateViewController(identifier:ID_TABBAR) as! UITabBarController
        self.navigationController?.pushViewController(tabBarController, animated:true)
}

Referenced from one of the responses from this post.

Update: In case your Tab Bar View Controller also happens to be the root view controller, the two lines of the code in the returnToTabbar method above can be:

self.dismiss(animated:true, completion:nil);
self.navigationController?.popViewController(animated:true);

(ref.: See answer here, for Swift4 but works just fine in Swift5)

David C.
  • 1,974
  • 2
  • 19
  • 29