相关疑难解决方法(0)

有条件地从AppDelegate开始在故事板中的不同位置

我有一个设置有工作登录和主视图控制器的故事板,后者是用户在登录成功时导航到的视图控制器.我的目标是在验证(存储在钥匙串中)成功时立即显示主视图控制器,如果验证失败则显示登录视图控制器.基本上,我想在AppDelegate中执行此操作:

// url request & response work fine, assume success is a BOOL here
// that indicates whether login was successful or not

if (success) {
          // 'push' main view controller
} else {
          // 'push' login view controller
}
Run Code Online (Sandbox Code Playgroud)

我知道方法performSegueWithIdentifier:但是这个方法是UIViewController的实例方法,所以不能从AppDelegate中调用.如何使用我现有的故事板来做到这一点?

编辑:

故事板的初始视图控制器现在是一个没有连接任何东西的导航控制器.我使用setRootViewController:区别因为MainIdentifier是一个UITabBarController.那么这就是我的线条:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{        
    BOOL isLoggedIn = ...;    // got from server response

    NSString *segueId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:segueId];

    if (isLoggedIn) { …
Run Code Online (Sandbox Code Playgroud)

objective-c storyboard uiapplicationdelegate segue

107
推荐指数
5
解决办法
5万
查看次数