这是我的故事板:
说我已登录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'
任何帮助将受到高度赞赏。非常感谢提前。
祝你有个美好的一天。
答案 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
比如
你应该会看到一个指向你的箭头SWRevealVC