iOS5 SplitViewController 在应用程序启动时在横向视图中使 BarButton 保持可见
我有一个 UISplitViewController,其中一个 UIViewController 作为主控制器,一个 UINavigationController 作为我的详细信息控制器(其中包含一个实际的DetailsController,因为它是 rootController)。
在 iOS5 中,在应用程序启动时(将设备保持在横向视图中),我将 splitViewController 的视图添加到我的窗口中,但随后我在 splitViewController 之上呈现一个登录控制器,如下所示:
- (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 很晚才意识到我处于横向状态,但在我到达细节控制器之前就发现了,所以一切都很酷。在 iOS 5 中,当我到达 splitViewController 时,第二个方法不会被调用。这意味着我留下了在横向视图中可见的 barButtonItem 。有趣的是,如果我旋转到纵向然后再回到横向,从那时起这些方法就会被正确调用。以前有人经历过这种情况吗?有什么解决办法吗?
I have a UISplitViewController with a UIViewController as master and a UINavigationController as my details controller (which contains an actual DetailsController as it's rootController).
In iOS5, at app startup (holding the device in landscape view), I add the splitViewController's view to my window but then I present a loginController on top of the splitViewController like this:
- (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;
}
As you can see the detailsController is my splitViewController's delegate. The problem is in iOS4, before the loginController gets displayed, the delegate method:
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)popoverController
is called then when I dismiss the loginController the delegate method:
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
gets called. I guess iOS realizes really late that I'm in landscape but figures out before I got to the detailController so everything was cool. In iOS 5, the second method does not get called by the time I get to the splitViewController. This means I'm left with the barButtonItem visible in landscape view. Funny enough, if I rotate to portrait then back to landscape, the methods gets called properly from then on. Anyone ever experienced this before? Any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到过类似的问题。应用程序启动后,我会显示登录 modalVC。但是当我关闭它时,detailViewController 中的 BarButtonItem 仍然可见。
只要使用
它就会神奇地开始工作。
I've had similar problem. After app launch I present Login modalVC. But when I dismiss it, the BarButtonItem in detailViewController is still visible.
Just use
and it will magically start working.
我最终将根控制器从导航控制器(登录时)切换为主菜单的 splitview 控制器:
I ended up switching the root controller from being a navigation controller (when logging in) to a splitview controller for the main menu: