在细节中使用 UINavigationController 时景观 UISplitViewController

发布于 2024-11-05 18:20:06 字数 1981 浏览 0 评论 0原文

我正在开发一个 iPad/通用应用程序,我面临着将 UINavigationController 作为 UISplitViewController 中的主要详细视图进行处理的问题。我想知道的是如何在横向时将默认侧面控制器按钮添加到详细控制器。

定义

分割视图控制器是这样定义的:

splitViewController = [[UISplitViewController alloc] init];

SideController *root = [[[SideController alloc] init] autorelease];
DetailController *detail = [[DetailController alloc] init];
InserisciDatiController *calcolo = [[[InserisciDatiController alloc]
                                     initWithNibName:@"InserisciDatiNuovi"
                                     bundle:[NSBundle mainBundle]]
                                    autorelease];

UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:root]autorelease];
UINavigationController *calcoloNav = [[[UINavigationController alloc] initWithRootViewController:calcolo] autorelease];

splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav, calcoloNav, nil];
splitViewController.delegate = detail;

稍后我释放所有可释放的对象。 我使用 SideController 作为详细控制器的一种索引。它有一个表视图,单击每一行我都会更新详细信息的主视图控制器。每个新控制器始终是 UINavigationController 的一个实例。

更新细节

myAppDelegate *delegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
UINavigationController *nav = (UINavigationController *)[delegate.splitViewController.viewControllers objectAtIndex:1];
[nav setViewControllers:[NSArray arrayWithObjects:controller, nil]];

当用户点击侧视图控制器中的一行时,我使用这段代码来更新细节控制器。

处理横向方向

当我想添加默认工具栏按钮以显示隐藏的侧视图控制器时,我想知道如何处理横向方向。我无法做的是使用此方法获取详细导航控制器的工具栏以添加按钮:

- (void)splitViewController:(UISplitViewController*)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem*)barButtonItem
       forPopoverController:(UIPopoverController*)pc

而且,当我将新控制器推送到导航控制器时,默认的后退按钮将出现在工具栏中。在这种情况下,我应该如何处理按钮的创建?

更新

请不要告诉我没有人遇到过这种问题!如何开发 iPad 应用程序?呜呜……

I am developing an iPad/Universal application, and I am facing the problem of handling a UINavigationController as the main detail view in a UISplitViewController. What I want to know is how to add the default side controller button to the detail controller when in landscape orientation.

Definition

The split view controller has been defined this way:

splitViewController = [[UISplitViewController alloc] init];

SideController *root = [[[SideController alloc] init] autorelease];
DetailController *detail = [[DetailController alloc] init];
InserisciDatiController *calcolo = [[[InserisciDatiController alloc]
                                     initWithNibName:@"InserisciDatiNuovi"
                                     bundle:[NSBundle mainBundle]]
                                    autorelease];

UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:root]autorelease];
UINavigationController *calcoloNav = [[[UINavigationController alloc] initWithRootViewController:calcolo] autorelease];

splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav, calcoloNav, nil];
splitViewController.delegate = detail;

and later on I release all the releasable objects.
I am using the SideController as a sort of index for the detail controller. It has a table view, and clicking each row I update the main view controller of the detail. Each new controller is always an instance of UINavigationController.

Update the detail

myAppDelegate *delegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
UINavigationController *nav = (UINavigationController *)[delegate.splitViewController.viewControllers objectAtIndex:1];
[nav setViewControllers:[NSArray arrayWithObjects:controller, nil]];

I use this piece of code to update the detail controller, when the user taps a row in the side view controller.

Handle landscape orientation

I'd like to know how to handle the landscape orientation, when I want to add the default toolbar button to display the hidden side view controller. What I am not able to do is getting the toolbar of the detail navigation controller to add the button using this method:

- (void)splitViewController:(UISplitViewController*)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem*)barButtonItem
       forPopoverController:(UIPopoverController*)pc

And also, when I push a new controller to the navigation controller the default back button will appear in the toolbar. In this case how should I handle the button creation?

Update

Please, do not tell me that no-one has ever had this kind of problem! How do you develop iPad apps? Sob ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

才能让你更想念 2024-11-12 18:20:06

我找到了一种对某人有用的方法,尽管我并不真正认为这是处理导航控制器的干净方法。

在分割视图控制器委托中,我以这种方式实现了 splitViewController:willHideViewController:withBarButtonItem:forPopoverController: 方法:

- (void)splitViewController:(UISplitViewController*)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem*)barButtonItem
       forPopoverController:(UIPopoverController*)pc
{
    barButtonItem.title = NSLocalizedString(@"menu", nil);

    myAppDelegate *app = (myAppDelegate *)[[UIApplication sharedApplication] delegate];

    UINavigationController *nav = [app.splitViewController.viewControllers objectAtIndex:1];
    UIViewController *ctrl = [nav.viewControllers objectAtIndex:0];

    if (!ctrl.navigationItem.backBarButtonItem && !ctrl.navigationItem.leftBarButtonItem) {
        ctrl.navigationItem.leftBarButtonItem = barButtonItem;
    }
}

这里我呈现栏按钮项目,它将显示代表侧视图控制器的弹出视图当且仅当导航控制器不显示后退按钮或其他自定义左按钮项目。

希望这对某人有帮助!

I found a way that could be useful for someone, even though I do not really think this is a clean way of handling the navigation controller.

In the split view controller delegate I implemented the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: method this way:

- (void)splitViewController:(UISplitViewController*)svc
     willHideViewController:(UIViewController *)aViewController
          withBarButtonItem:(UIBarButtonItem*)barButtonItem
       forPopoverController:(UIPopoverController*)pc
{
    barButtonItem.title = NSLocalizedString(@"menu", nil);

    myAppDelegate *app = (myAppDelegate *)[[UIApplication sharedApplication] delegate];

    UINavigationController *nav = [app.splitViewController.viewControllers objectAtIndex:1];
    UIViewController *ctrl = [nav.viewControllers objectAtIndex:0];

    if (!ctrl.navigationItem.backBarButtonItem && !ctrl.navigationItem.leftBarButtonItem) {
        ctrl.navigationItem.leftBarButtonItem = barButtonItem;
    }
}

Here I present the bar button item that will show the popover view representing the side view controller if and only if the navigation controller is not showing the back button or another custom left button item.

Hope this helps someone!

半窗疏影 2024-11-12 18:20:06

我相信 Alterplay 的 Slava Bushtruk 已经找到了您正在寻找的内容,并在他的 APSplitViewController 库。

I believe that Slava Bushtruk of Alterplay has worked out what you're looking for and used it in his APSplitViewController library.

旧伤还要旧人安 2024-11-12 18:20:06

我认为您没有得到任何好的答案的原因是很难理解您的问题,即您的问题可以更清楚。
首先让我看看我是否正确理解了这个问题。当您在导航控制器上推送某些内容并且应该显示后退按钮和分割视图按钮时,您是否不知道如何处理这种情况?

如果是这样,我们解决该问题的方法是分割视图按钮仅在导航控制器的根目录中可见。无论如何,侧面控制器通常只与详细视图的根视图控制器相关。

如果我误解了您的问题或者我的解决方案不适用于您的项目,请告诉我。

编辑:因此,如果您坚持这样做,可以采用以下方法:

toolbar = [[UIToolbar alloc] initWithFrame:(UIInterfaceOrientationIsPortrait(interfaceOrientation)) ? CGRectMake(0, 0, 768, 44) : CGRectMake(0, 0, 703, 44)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.navigationController.navigationBar addSubview:toolbar];

viewWillDisappear:

[self setToolbarHidden:YES animated:animated];

viewWillAppear:

[self setToolbarHidden:NO animated:animated];

,现在您有了一个工具栏你可以添加任何东西。好吧,任何可以添加到 UIToolbar 中的东西,几乎都是任何东西。

I think the reason you haven't gotten any good answers is that it's really hard to understand your problem, i.e., your question could be clearer.
So first let me see if I've understood the problem correctly. Is the problem that you don't know how to handle the case when you've pushed something on your navigation controller and is supposed to show both the back button and the split view button?

If so, the way we've solved that problem is that the split view button is only visible in the root of the navigation controller. The side controller is usually only relevant for the detail view's root view controller anyway.

If I've misunderstood your problem or my solution isn't applicable to your project, please let me know.

EDIT: So if you insist on doing this, here's a way to do it:

toolbar = [[UIToolbar alloc] initWithFrame:(UIInterfaceOrientationIsPortrait(interfaceOrientation)) ? CGRectMake(0, 0, 768, 44) : CGRectMake(0, 0, 703, 44)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.navigationController.navigationBar addSubview:toolbar];

On viewWillDisappear:

[self setToolbarHidden:YES animated:animated];

and on viewWillAppear:

[self setToolbarHidden:NO animated:animated];

Now you have a toolbar that you can add anything to. Well, anything that can be added to a UIToolbar anyway, which is almost anything.

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