Reputation: 171
I am trying to segue from a tab view controller into a view controller. The segue is present modally. The code is below:
override func viewDidAppear(_ animated: Bool) {
if (UserDefaults.standard.bool(forKey: "HasLaunchedOnce")) {
print("LAnched B4")
performSegue(withIdentifier: "Tutorial", sender: nil)
} else {
UserDefaults.standard.set(true, forKey: "HasLaunchedOnce")
UserDefaults.standard.synchronize()
performSegue(withIdentifier: "Tutorial", sender: nil)
}
}
The problem I'm having is that there is no segue that happens, the first view controller on the tab bar is shown first. Is there a way to prioritise the segue?
Upvotes: 1
Views: 281
Reputation: 1519
Yes Follow below code for achieving your task you just need to add the below function in your controller
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Tutorial" {
print("INSIDE TAB")
if let tabVC = segue.destination as? UITabBarController{
if !User().getIsLoggedIn() {
print("INSIDE")
tabVC.selectedIndex = 2 // Or you can give your viewController index
}
}
}
}
Remember these index will start from
0
to the last. so according to your requirement check your segue condition and prepare that segue for the desired index.
Upvotes: 1