S
S
Sunset_over2015-08-18 11:24:23
Objective-C
Sunset_over, 2015-08-18 11:24:23

How to change initial View Controller?

Good afternoon, I have a login form in the application, I need to change the intial View Controller in the storyboard after user authorization. That is, after authorization, the initial page would not be a login form, a user profile.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
ManWithBear, 2015-08-18
@Sunset_over

The best way would be to initialize the view controller not through the storyboard, but in the method

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

You can pull the controller out of the storyboard, or make two different storyboards, one for the login/registration screens and the other for the application itself. In this case, the main storyboard is the first one, but if there is no user data, use the second one.

@
@ailinykh, 2015-08-18
_

1) In the Storyboard , provide the association ID between the authorization controller and the user profile.
2) In authorization controller, if user is authorized, use
- performSegueWithIdentifier:sender:

A
Alexander Tikhonov, 2015-08-18
@tikhonov666

I took the advice of ManWithBear and made this sketch

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let logined = true
        var vc: UIViewController?
        if !logined {
            vc = storyboard.instantiateViewControllerWithIdentifier("loginVC")
        } else {
            vc = storyboard.instantiateInitialViewController()
        }
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.rootViewController = vc
        window?.makeKeyAndVisible()
        return true
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question