iOS5 SplitViewController 在应用程序启动时在横向视图中使 BarButton 保持可见

发布于 2024-12-27 03:18:34 字数 2625 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪漫之都 2025-01-03 03:18:34

我也遇到过类似的问题。应用程序启动后,我会显示登录 modalVC。但是当我关闭它时,detailViewController 中的 BarButtonItem 仍然可见。

只要使用

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

它就会神奇地开始工作。

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

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

and it will magically start working.

爱人如己 2025-01-03 03:18:34

我最终将根控制器从导航控制器(登录时)切换为主菜单的 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];
} 

I ended up switching the root controller from being a navigation controller (when logging in) to a splitview controller for the main menu:

-(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];
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文