我最近为我的应用程序编写教程。我使用本教程创建了教程:
http://www.appcoda.com/uipageviewcontroller-tutorial-intro/
我创建了一个“按钮”,将用户带回到rootViewController
. 在本例中为TabBarController
. 问题是:在本教程中,我为教程制作了一个额外的故事板。rootViewController(TabBarController)
那么我怎样才能用按钮回到原来的状态呢?
代码:
- (IBAction)start:(id)sender {
UIViewController* backToRootViewController = [[UIViewController alloc] initWithNibName:@"TabBarController" bundle:[NSBundle mainBundle]];
[self.view addSubview:backToRootViewController.view];
}
这也行不通
- (IBAction)start:(id)sender {
[self.navigationController popToRootViewControllerAnimated:YES];
}
编辑
在第一次开始时打开教程:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
if (!isAccepted) {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[APPViewController alloc] initWithNibName:@"APPViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
}
APPViewController
是教程
编辑
在 johnnelm9r 的帮助下,当前代码是这样的:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"main" bundle: nil];
IntroViewController *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"IntroViewController"];
BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
if (!isAccepted) {
[self.window.rootViewController presentViewController:introViewController animated:NO completion:nil];
}
但是现在,可悲的是,应用程序崩溃了,错误是:
Application tried to present a nil modal view controller on target <UITabBarController: 0x175409d0>.'
还有一个警告:Incompatible pointer type assigning to 'ViewController' from 'UIViewController' in AppDelegate