我有一个UISplitViewController,其中UIViewController作为主对象,UINavigationController作为我的详细信息控制器(它包含一个实际的DetailsController作为rootController)。

在iOS5中,在应用启动时(将设备保持在横向视图中),我将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在横向视图中可见。有趣的是,如果我旋转到纵向然后又回到横向,则此后将正确调用这些方法。有人曾经经历过吗?有什么办法吗?

最佳答案

我有类似的问题。应用启动后,我将显示Login modalVC。但是当我关闭它时,detailViewController中的BarButtonItem仍然可见。

只需使用

[self performSelector:@selector(presentLogin) withObject:nil afterDelay:0.1]


它将神奇地开始工作。

关于ios - 在启动应用程序的横向 View 中,iOS5 SplitViewController使BarButton可见,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8842921/

10-11 19:59