Can use SegueWithIdentifier with AppDelegate?

I am working on an application that, at startup, checks for the correct credentials, and if they are found and have not expired, the main manager of the split views is displayed, and if the login screen is not displayed.

Each part works fine individually, but during startup I try to choose the best view to display in the best way.

I tried to configure the modal segment from the root view controller, and in my application: didFinishLaunchingWithOptions: function in the App Delegate by calling this:

// Segue to the login view controller...
if (loginNeeded) {
    [self.window.rootViewController performSegueWithIdentifier:@"LoginScreen" sender:self];
}

This should work logically, but starting sessions from the application delegate seems impossible.

What is the ideal place and technique for this?

+5
source share
5

segue, hiding-a-segue-on-login-process.

, , , , - ...

, , , UIViewController. , (, ).

SplitViewController. "Load SplitViewController" segue, FullyReplaceSegue.

.m :

[self performSegueWithIdentifier:@"Load SplitViewController" sender:self];

segue UIStoryboardSegue FullyReplaceSegue .

.h

#import <UIKit/UIKit.h>
@interface  : UIStoryboardSegue

@end

.m file

#import "FullyReplaceSegue.h"

@implementation FullyReplaceSegue

- (void)perform
{
    UIViewController *dest = (UIViewController *) super.destinationViewController;
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.rootViewController = dest;

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UISplitViewController *splitViewController = (UISplitViewController *)dest;  // assumes we're transitioning to a UISplitViewController!
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;
    }
}

@end
+4

.

didFinishLaunchingWithOptions:

//save the root view controller
[[self window] makeKeyAndVisible];
UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;
rootController = [[navigationController viewControllers] objectAtIndex:0];

- :

[rootController performSegueWithIdentifier:@"fileSegueID" sender:self];

segue , "rootController", fileSegueID. , , rootController .

+4

, , . .

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Signup" bundle:nil];
    if(isLoggedIn) {
    UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;
    IndexController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"IndexController"];
    [navigationController pushViewController:ivc animated:NO];
}
+2

, , , ( ), viewDidLoad , . , .

+1

, , segue. :

UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;

[[[navigationController viewControllers] objectAtIndex:0] performSegueWithIdentifier:@"LoginScreen" sender:self];

, viewControllers , , . ( ).

Seg ("LoginScreen") should not be attached to an action. The way you do this is to drag control from the file owner icon at the bottom of the scene to the destination scene. A pop-up window will appear in which the option in the "Manual Segue" will be requested; select type "Push". Click on the small square and make sure you are in the Attributes Inspector. Give it the identifier that you will use to refer to it in the code.

0
source

All Articles