我需要能够绕过在XCode中选择导航控制器项目类型时获得的默认RootViewController。我需要这个,因为我想根据应用程序是否已配置而进入不同的路径(如果没有,则注册/登录屏幕)。有人能指出一个例子,在AppDelegate中,NavigationController是通过代码挂钩到另一个控制器(在本例中是SignupController)吗?
这是我所拥有的,但它不会让我改变标题。在MainWindow.xib中,它仍然绑定在默认的RootViewController中。
(void)applicationDidFinishLaunching:(UIApplication *)application {
[[UIApplication sharedApplication]
// if no config, load up the SignupController
SignupController* signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
答案 0 :(得分:2)
您可以这样做:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
if( hasConfig ) {
[window addSubview:[navigationController view]];
} else {
SignupController *signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil];
[window addSubview:signupController.view];
[signupController release];
}
[window makeKeyAndVisible];
登录完成后切换回导航控制器会变得很尴尬。 (假设你在屏幕上显示一个标志。)
为什么不使用modalviewcontroller?
在 RootViewController.m :
中- (void)viewDidAppear {
[super viewDidAppear];
if( notLoggedIn ) {
SignupController *signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil];
[self presentModalViewController: signupController animated:YES];
[signupController release];
}
}
<强> SignupController.m 强>
- (void)didSignInOk {
//this will dismiss the sign in screen
[self.parentViewController dismissModalViewController];
}