Jabi
Jabi

Reputation: 151

Using the same item of a tab bar controller, is it possible to instantiate alternate views based on the value of a boolean property?

Between 2 user types, if either of the users clicks on 'Item 1' of a tab bar controller, is it possible to direct to different view controllers depending on the value of a boolean property for that user?

Upvotes: 1

Views: 63

Answers (1)

zeytin
zeytin

Reputation: 5643

Sure, i think your user type coming from back end according to your id. So you can do something like below.

struct User {
 salesPerson = false
 // other properties
}

let user = User()
if user.salesPerson { // that means salesPerson is true
let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main)
.instantiateViewController(withIdentifier: "SalesPersonViewController") as? SalesPersonViewController
self.navigationController?.pushViewController(vc!, animated: true)
} else { // that means false so you can push other vc
let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main)
.instantiateViewController(withIdentifier: "AdminViewController") as? AdminViewController
self.navigationController?.pushViewController(vc!, animated: true)
}

Upvotes: 1

Related Questions