登录后将SWRevealViewController设为rootViewController,当tabbarController为sw_front objC时

时间:2017-11-17 20:29:25

标签: ios objective-c uitabbarcontroller swrevealviewcontroller rootviewcontroller

这是我的故事板:

enter image description here

说我已登录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 delegateSignInViewController

- (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' 任何帮助将受到高度赞赏。非常感谢提前。
祝你有个美好的一天。

2 个答案:

答案 0 :(得分:0)

我需要做的就是:

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

只需将SWRevealViewController设置为项目的rootViewController即可。 :)

答案 1 :(得分: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比如image below

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