0

这是我的故事板:

在此处输入图像描述

假设我在这些上方有一个登录viewController,并且我想从那里SWRevealViewController作为我的rootViewController,这样它就可以完美地工作。使用下面的代码,leftMenuViewController我可以完美地选择我的 tabBar ViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITabBarController *tabBarController = (UITabBarController *)self.revealViewController.frontViewController;
    UINavigationController *navController = tabBarController.viewControllers[indexPath.row];
    [navController popToRootViewControllerAnimated:NO];
    tabBarController.selectedIndex = indexPath.row;
    self.revealViewController.rearViewRevealOverdraw = 0.0f;
    [self.revealViewController pushFrontViewController:tabBarController animated:YES];
}

App delegate但它在或 中不起作用SignInViewController

- (void)checkIfUserSignedIn
{
    if ([ManagerClass getBOOLTypeUserDefaultForKey:@"isSignedIn"] == YES) {
        UITabBarController *tabBarController = (UITabBarController *)self.revealViewController.frontViewController;
        UINavigationController *navController = tabBarController.viewControllers[0];
        [navController popToRootViewControllerAnimated:NO];
        tabBarController.selectedIndex = 0;
        self.revealViewController.rearViewRevealOverdraw = 0.0f;
        [self.revealViewController pushFrontViewController:tabBarController animated:YES];
        self.window.rootViewController = tabBarController;
    } else {

    }
}

它在日志中给出:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch' 任何帮助将不胜感激。提前非常感谢。
祝你有美好的一天。

4

2 回答 2

0

您上面的答案是正确的,但是您在问题中提到的崩溃

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'

是由您引起的,storyboard因为SWRevealVC您在上面发布的图像中未设置为初始视图控制器,请选择您的视图控制器,然后从属性检查器中检查可用的选项,Is Initial View Controller例如下图

你应该看到一个箭头指向你SWRevealVC

于 2017-11-20T06:12:50.113 回答
0

我需要做的就是:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:mainStoryboard bundle:[NSBundle mainBundle]];
        SWRevealViewController *controller = (SWRevealViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"RevealViewControllerID"];
        [self.window setRootViewController:controller];

只需设置SWRevealViewController为您rootViewController的项目。:)

于 2017-11-17T21:37:42.697 回答