我有一个UISplitViewController,UIViewController作为主,UINavigationController作为我的细节控制器(它包含一个实际的DetailsController,因为它是rootController)。
在iOS5中,在app启动时(在横向视图中保存设备),我将splitViewController的视图添加到我的窗口,但是我在splitViewController之上提供了一个loginController,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
KRMasterViewController *masterViewController = [[[KRMasterViewController alloc] initWithNibName:@"KRMasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
KRDetailViewController *detailViewController = [[[KRDetailViewController alloc] initWithNibName:@"KRDetailViewController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
[self.window addSubview:self.splitViewController.view];
LoginController *controller=[[LoginController alloc]
initWithNibName:@"LoginController" bundle:nil];
[self.splitViewController presentModalViewController:controller animated:false];
[self.window makeKeyAndVisible];
return YES;
}
正如您所看到的,detailsController是我的splitViewController的委托。问题出在iOS4中,在显示loginController之前,委托方法:
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)popoverController
当我解除loginController委托方法时,被调用:
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
被调用。我想iOS实现的很晚,我在风景中,但在我到达detailController之前弄明白所以一切都很酷。在iOS 5中,第二种方法在我到达splitViewController时不会被调用。这意味着我在横向视图中可以看到barButtonItem。有趣的是,如果我旋转到肖像然后再回到横向,那么从那时开始就可以正确调用这些方法。以前有人经历过这个吗?任何解决方案?
答案 0 :(得分:0)
我遇到过类似的问题。应用程序启动后,我提出登录modalVC。但是当我解雇它时,detailViewController中的BarButtonItem仍然可见。
只需使用
[self performSelector:@selector(presentLogin) withObject:nil afterDelay:0.1]
它会神奇地开始工作。
答案 1 :(得分:0)
我最终将根控制器从导航控制器(登录时)切换到主菜单的splitview控制器:
-(void)goToLogin{
self.rootSplitController=nil;
UINavigationController* navController=[[UINavigationController alloc]init];
navController.navigationBarHidden = true;
self.rootNavController=navController;
[navController release];
LoginController *loginController=[[LoginController alloc]init];
[self.rootNavController pushViewController:loginController animated:false];
[loginController release];
[self.window addSubview:self.rootNavController.view];
}
-(void)goToMain{
self.rootNavController=nil;
MasterController *masterViewController = [[[MasterController alloc]
initWithNibName:@"MasterController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc]
initWithRootViewController:masterViewController] autorelease];
masterNavigationController.navigationBarHidden=true;
DetailsController *detailViewController = [[[DetailsController alloc]
initWithNibName:@"DetailsController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc]
initWithRootViewController:detailViewController] autorelease];
detailNavigationController.navigationBarHidden=true;
self.rootSplitController = [[[UISplitViewController alloc] init] autorelease];
self.rootSplitController.delegate = detailViewController;
self.rootSplitController.viewControllers = [NSArray arrayWithObjects:
masterNavigationController, detailNavigationController, nil];
[self.window addSubview:self.rootSplitController.view];
}