Reputation: 4122
I am using a tab bar controller and I wonder if there is a way to check which tab is being clicked?
If the user clicks on the "account" tab and is not logged in I want to redirect to a full screen modal login screen instead of the account VC.
Upvotes: 1
Views: 5545
Reputation: 4281
The options that others have provided are fine, but I wanted to let you know of another way. In the viewWillAppear, viewDidAppear, or viewDidLoad functions, you can call what you need to segue to a login ViewController
Upvotes: 0
Reputation: 944
You can do it in your custom UITabBarController or somewhere, and override the 'didSelectItem' function.
import UIKit
class TabbarViewController: UITabBarController {
override func viewDidLoad() {
}
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
print("Selected Index :\(self.selectedIndex)");
}
}
Upvotes: 6
Reputation: 115
In the scenario you outlined, I would check to see if current user is logged in or not, and if not segue to the appropriate screen of your application.
Upvotes: 0