Vote count:
0
So in my AppDelegate I have declared my tab controller and views etc However if there is no user logged in, then the code is executed at login, however I need it to be executed again once the user has successfuly logged in.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.tintColor = uicolorFromHex(0xffffff)
navigationBarAppearance.barTintColor = uicolorFromHex(0x4183D7)
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
navigationBarAppearance.titleTextAttributes = titleDict
//navigationBarAppearance.clipsToBounds = true;
let tabBarController = UITabBarController()
let storyboard = UIStoryboard(name: "Storyboard", bundle: nil)
let myVC2 = storyboard.instantiateViewControllerWithIdentifier("navProfile") as UIViewController
let myVC1 = storyboard.instantiateViewControllerWithIdentifier("navigation") as UIViewController
let myVC3 = storyboard.instantiateViewControllerWithIdentifier("navComp") as UIViewController
var controllers = [myVC1,myVC2]
tabBarController.viewControllers = controllers
self.window?.rootViewController = tabBarController
if PFUser.currentUser() != nil{
var query = PFUser.query()
query.whereKey("objectId", equalTo: PFUser.currentUser().objectId)
query.findObjectsInBackgroundWithBlock {
(results: [AnyObject]!, error: NSError!) -> Void in
for listing in results {
var usertype = listing["UserType"] as? String
if usertype == "Student"{
var controllers = [myVC1,myVC2]
tabBarController.viewControllers = controllers
self.window?.rootViewController = tabBarController
}
else if usertype == "Employer" {
var controllers = [myVC1,myVC3]
tabBarController.viewControllers = controllers
self.window?.rootViewController = tabBarController
}
}
}
}
asked 23 secs ago
Tab Bar Controller linked to different views depending on user role - iOS Swift
Aucun commentaire:
Enregistrer un commentaire