我是UISplitView开发的新手,所以我确信有一些明显我做错了。我有一个基本的UISplitView iPad应用程序,在应用程序启动时加载两个UITableView控制器。这很好用。
我想要做的就是在启动时立即提供模态的“身份验证”视图,以便用户在继续之前需要登录。这是我到目前为止编写的代码,它编译和工作没有中断,但视图没有显示。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
masterViewController.detailViewController = detailViewController;
masterViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.splitViewController;
[self presentAuthenticate];
[self.window makeKeyAndVisible];
applicationDidLaunch = YES;
return applicationDidLaunch;
}
- (void) presentAuthenticate {
AuthenticateViewController *loginController = [[AuthenticateViewController alloc] initWithNibName:@"AuthenticateViewController" bundle:nil];
[loginController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[loginController setModalPresentationStyle:UIModalPresentationFormSheet];
if ([self.splitViewController respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self.splitViewController presentViewController:loginController animated:NO completion:nil];
} else {
[self.splitViewController presentModalViewController:loginController animated:NO]; //iOS 4 works fine with or without animation
}
}
我将AuthenticateViewController定义为一个视图,其中包含一些文本字段,并将其连接到文件的所有者视图。
提前致谢!
答案 0 :(得分:2)
除非视图完全加载,否则视图控制器不允许在另一视图上推送/显示。
简单地说我们不允许在viewcontroller viewDidLoad / viewWillAppear中调用presentModalViewController / pushViewController。我们需要在viewDidAppear中调用它。
我说你遇到了同样的问题。
我可以说是一些解决方案,
感谢,
Naveen Shan