以模态方式呈现的 UIPopoverController 在 iOS 5 中不起作用
首先,我们可以在这里谈谈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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了。 setModalInPopover 赋值必须位于嵌入式视图控制器的 viewDidAppear 方法内部,以使弹出窗口成为模态:
I found it. The setModalInPopover assignment must be inside of the viewDidAppear method of the embedded view controller for the popover to be modal:
如果您使用知道视图将位于弹出窗口中的自定义视图控制器,则批准的答案将起作用。但是,如果您使用的是以编程方式创建的通用视图控制器,或者您出于某种原因无法重写其
viewDidAppear
方法的视图控制器,则还可以实现UIPopoverControllerDelegate
类中的协议,在popoverControllerShouldDismissPopover
中将 popover 委托设置为该类并返回 NO。示例
在实现 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 theUIPopoverControllerDelegate
protocol in a class, set the popover delegate to that class and return NO, in thepopoverControllerShouldDismissPopover
.Example
In some class that implements UIPopoverControllerDelegate:
In the code that creates your popover controller:
您是否尝试过设置导航控制器的 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 itsmodalInPopover
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.