Hello i have a login screen and registration screen in a nav controller for when a user signs in or wants to sign up in an application. I also created a Tab controller that displays the home page screen. After the user signs in or signs up i want to be able to segue to the tab controller and make this the root view controller and thus the user cannot go back to the sign in or register page. Please how can this be accomplished?
Below is few lines of code when the user signs in
if statusCode == 200 {
do {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
let result = json as? [String: AnyObject]
guard let token = result!["token"], let firstname = result!["user"]!["firstname"]! else {
print("Error: \(error?.debugDescription)")
return
}
NSUserDefaults.standardUserDefaults().setObject(token, forKey: "token")
//code to segue to the tab controller from the nav controller (login screen)
self.getHome()
}
catch {
print("Error receiving data")
}
}
})
task.resume()
func getHome() {
let storyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tableController = storyboard.instantiateViewControllerWithIdentifier("tabController") as? UITableViewController
let appledDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appledDelegate.window?.rootViewController = tableController
}
in my AppDelegate.swift in file i check to see if there is a token if not calls the Login page or show home page:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let obj = NSUserDefaults.standardUserDefaults().objectForKey("token")
if obj == nil {
let welcomeHomeController:UIViewController = WelcomeHomeController(nibName: nil, bundle: nil)
welcomeHomeController.view.backgroundColor = UIColor.whiteColor()
let navController:UINavigationController = UINavigationController(rootViewController: welcomeHomeController)
//create window
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.backgroundColor = UIColor.darkGrayColor()
self.window?.rootViewController = navController
self.window!.makeKeyAndVisible()
return true
}