如何在 iPhone 上的 UIPopoverController 中显示 NavigationController 背景

发布于 01-05 08:21 字数 1037 浏览 5 评论 0 原文

如何在 iPhone 上的 UIPopovercontroller 中显示 NavigationController 的背景(包括标题/按钮)?

目前看起来像这样:

在此处输入图像描述

在我的 PopoverView-ViewController 中:

- (void)viewDidLoad
{
[super viewDidLoad];

self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;

self.navigationItem.title = @"self.navigationItem.title";
}

< strong>调用 Popover 时:

InfoView *iv = [[InfoView alloc] initWithNibName:@"InfoView" bundle:nil];


    UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];


    self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
    [self.pop setDelegate:self];
    [self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

应该如下所示:

在此处输入图像描述

How can i display the background of the NavigationController (including title/buttons) in my UIPopovercontroller on the iPhone?

At the moment it looks like that:

enter image description here

In my PopoverView-ViewController:

- (void)viewDidLoad
{
[super viewDidLoad];

self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;

self.navigationItem.title = @"self.navigationItem.title";
}

When calling Popover:

InfoView *iv = [[InfoView alloc] initWithNibName:@"InfoView" bundle:nil];


    UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];


    self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
    [self.pop setDelegate:self];
    [self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

It should look like this:

enter image description here

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

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

发布评论

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

评论(5

影子是时光的心 2025-01-12 08:21:01

首先 UINavigationController 没有自己的背景,它显示内容视图控制器的背景。如果您可以成功地使用导航控制器显示弹出窗口,请检查您的 InfoView。它的观点有什么背景吗?

其次,我尝试在iPhone上以不同的配置多次执行你的代码,但总是收到错误

由于未捕获的异常而终止应用程序
'NSInvalidArgumentException',原因:'-[UIPopoverController
initWithContentViewController:] 在未运行时调用
UIUserInterfaceIdiomPad

这对我来说并不奇怪。即使你能成功,苹果也可能会拒绝你的申请。
2.1 崩溃的应用程序将被拒绝 - 只需在多个设备上测试您的代码并查看结果。

At first UINavigationController doesn't have own background, it shows background of content view controller. If you can show popover with navigation controller successfully, then check your InfoView. Does it's view has some background?

Second, I tried to execute your code multiple times in different configurations on iPhone, but always have received error

Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIPopoverController
initWithContentViewController:] called when not running under
UIUserInterfaceIdiomPad
.

And that was not surprise for me. Even if you could make it work, then Apple may reject your application.
2.1 Apps that crash will be rejected - Just test your code on several devices and see result.

不再让梦枯萎 2025-01-12 08:21:01

您的代码

InfoView *iv = [[InfoView alloc] initWithNibName:@"InfoView" bundle:nil];


UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];


self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

是完美的,只需隐藏默认导航控制器并在 InfoView.xib 的 XIB 中添加一个 navigationBar 并在那里编写 cancelButtonAction 来执行视图的解除或表格视图选择的详细信息。它工作正常,请检查我以相同方式完成的图像,并相信我它工作正常。在此处输入图像描述

your code

InfoView *iv = [[InfoView alloc] initWithNibName:@"InfoView" bundle:nil];


UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];


self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

is perfect just hide the default navigation controller and add a navigationBar in the XIB of InfoView.xib and write the cancelButtonAction there to perform the dismissal of the view or the detail of the tableview selection. It Works fine, Please check the image i have done the same way, and believe me it works fine.enter image description here

岁月流歌 2025-01-12 08:21:01

将其添加到代码行 [self.pop presentPopoverFromBarButtonItem:se.. 之前:

uc.modalPresentationStyle = UIModalPresentationCurrentContext;

请参阅 "="">modalPresentationStyle 属性。

Add this to your code before the line [self.pop presentPopoverFromBarButtonItem:se..:

uc.modalPresentationStyle = UIModalPresentationCurrentContext;

See the documentation for the modalPresentationStyle property.

蓝海似她心 2025-01-12 08:21:01

我认为您需要为 InfoView 控制器粘贴更多代码,因为我怀疑这就是问题所在。

I think you'll need to paste in more of the code for your InfoView controller, as I suspect that's where the problem is.

孤千羽 2025-01-12 08:21:01

您是否尝试过将背景视图设置为班级?

    [pop setPopoverBackgroundViewClass:bgView];

Have you tried setting up your background view as a class?

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