以模态方式呈现的 UIPopoverController 在 iOS 5 中不起作用

发布于 2024-12-10 06:55:11 字数 1079 浏览 5 评论 0原文

首先,我们可以在这里谈谈iOS 5吗?还是仍处于 NDA 之下? 如果我们不能讨论这个问题,请忽略我的问题。

通过使用安装了 iOS 5 的 iPad 测试我的应用程序,我发现了我的“模态”弹出窗口的一个问题:可以通过点击它的外部来关闭它,换句话说,它不是模态的!我不知道我做错了什么。

视图控制器使用以下代码打开弹出窗口:

AddProjectViewController *addProjectViewController = [[AddProjectViewController alloc] initWithStyle:UITableViewStyleGrouped];
[addProjectViewController setDelegate:self];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addProjectViewController];
[addProjectViewController release];

CGRect popoverFrame = [sender frame];

UIPopoverController *tempPopover = [[UIPopoverController alloc] initWithContentViewController:navController];
[tempPopover presentPopoverFromRect:popoverFrame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.currentPopover = tempPopover;
[tempPopover release];
[navController release];

弹出窗口内部的视图控制器的 viewDidLoad 中有这一行。

- (void)viewDidLoad
{
    [self setModalInPopover:YES];

    // Do other stuff
}

有什么遗漏吗?

First of all, can we talk about iOS 5 here? Or is it still under NDA?
If we can't talk about it, just ignore my question.

By testing my app with an iPad with iOS 5 installed I discovered a problem with my "modal" popover: This can be closed by tapping outside of it, in other words, it's not modal! I have no idea what I'm doing wrong.

A view controller opens the popover with this code:

AddProjectViewController *addProjectViewController = [[AddProjectViewController alloc] initWithStyle:UITableViewStyleGrouped];
[addProjectViewController setDelegate:self];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addProjectViewController];
[addProjectViewController release];

CGRect popoverFrame = [sender frame];

UIPopoverController *tempPopover = [[UIPopoverController alloc] initWithContentViewController:navController];
[tempPopover presentPopoverFromRect:popoverFrame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.currentPopover = tempPopover;
[tempPopover release];
[navController release];

The view controller that's inside of the popover has this line in it's viewDidLoad.

- (void)viewDidLoad
{
    [self setModalInPopover:YES];

    // Do other stuff
}

Is there anything missing?

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

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

发布评论

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

评论(3

冷默言语 2024-12-17 06:55:11

我找到了。 setModalInPopover 赋值必须位于嵌入式视图控制器的 viewDidAppear 方法内部,以使弹出窗口成为模态:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [self setModalInPopover:YES];
}

I found it. The setModalInPopover assignment must be inside of the viewDidAppear method of the embedded view controller for the popover to be modal:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [self setModalInPopover:YES];
}
白衬杉格子梦 2024-12-17 06:55:11

如果您使用知道视图将位于弹出窗口中的自定义视图控制器,则批准的答案将起作用。但是,如果您使用的是以编程方式创建的通用视图控制器,或者您出于某种原因无法重写其 viewDidAppear 方法的视图控制器,则还可以实现 UIPopoverControllerDelegate 类中的协议,在 popoverControllerShouldDismissPopover 中将 popover 委托设置为该类并返回 NO。

示例

在实现 UIPopoverControllerDelegate 的某个类中:

- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *) popoverController {
    return NO;
}

在创建弹出窗口控制器的代码中:

UIPopoverController * pc = initialize and setup 

pc.delegate = instance of class that impleements UIPopoverControllerDelegate

The approved answer will work if you are using a custom view controller that knows the view is going to be a in a popover. However, if you are using a generic view controller created programmatically or a view controller whose viewDidAppear method you do not have the ability to override for whatever reason, you can also implement the UIPopoverControllerDelegate protocol in a class, set the popover delegate to that class and return NO, in the popoverControllerShouldDismissPopover.

Example

In some class that implements UIPopoverControllerDelegate:

- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *) popoverController {
    return NO;
}

In the code that creates your popover controller:

UIPopoverController * pc = initialize and setup 

pc.delegate = instance of class that impleements UIPopoverControllerDelegate
久光 2024-12-17 06:55:11

您是否尝试过设置导航控制器的 modalInPopover 属性?这是实际上由弹出窗口“拥有”的视图控制器,因此我希望弹出窗口使用其 modalInPopover 属性来确定它是否是模态的。

也许 UINavigationController 确实将其传递给了 iOS 4.x 中当前可见的子视图控制器。

Have you tried setting the modalInPopover property of the navigation controller? This is the view controller that is actually "owned" by the popover, so I would expect that the popover uses its modalInPopover property to determine whether it is modal or not.

Perhaps UINavigationController did pass this on to its currently visible child view controller in iOS 4.x.

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