如何使我的应用程序始终从第二个视图开始



我有一个Web服务应用程序,它有alogin视图。我想让我的应用程序的登录视图在第一次加载(安装)应用程序时出现,之后它必须从第二个视图开始。我该怎么做?在这个链接中有一些解决方案,但我认为这不是我想要的。由于我的是一个web服务,意味着第二个视图的内容(我想一直推送)是从服务器上获取的(我使用NSJSONSerialization类来完成这项工作)

我会将登录视图作为一个模式视图,只有在需要时才会显示。

编辑:这是非常简短的:(我假设你正在使用ARC。)

在AppDelegate中:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: mySecondViewController];
if (![self isUserLoggedIn]) {
    MyLogInViewController *logInViewController = [[MyLogInViewController alloc] init];
    [self presentModalViewController: MyLogInViewController animated: YES];
}
[[self window] setRootViewController: [self navigationController]];

和在logInViewController:中

- (void)logInSuccessful {
    [self dismissModalViewControllerAnimated: YES];
}

相关内容

最新更新