如何正确实例化 PopoverController

发布于 2024-10-13 20:29:19 字数 2065 浏览 5 评论 0原文

我有一个 SplitviewController ,其中包含多个可能的 DetailviewsWebviewsTableviews、常规 UIViews )。

例如,我在顶部有一个 NavigationController,然后浏览一些表格。

最后我展示了一些Content,比如说一个UIWebview。我将 iPad 旋转为纵向,并在工具栏中添加一个 Button,从中显示 popOverController

Buttonclick 上,我说:

if (!popoverController) {

if (self.view.window != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:  [appDelegateiPad naviPad]];

popoverController.delegate = self;

 }
}

在这里,我实例化一个 PopOverController,而 Content 是 splitview 的左侧部分,从我离开的位置开始。一切都很好。

但是当我旋转时,我收到此警告:

CoreAnimation: ignoring exception: Popovers cannot be presented from a view which does not have a window.

在屏幕上,popOverController 重新出现,内容为空内容(我会说是黑色半透明),但我不知道为什么,因为我忽略了它,并且不能再有另一个实例,因为我只创建了一个实例单击按钮时。

这几天来这让我发疯。

感谢任何(!)帮助!

-(void) showPopOver:(id) sender {




NSLog(@"showing popover?");

if (!popoverController) {

    if (self.view.window != nil) {
        popoverController = [[UIPopoverController alloc] initWithContentViewController:[appDelegateiPad naviPad]];
        //RootViewController *r = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle: nil];
        //  popoverController = [[UIPopoverController alloc] initWithContentViewController:r];
        //popoverController.popoverContentSize = CGSizeMake(320, 800);
        //popoverController.delegate = self;
    }
 }


if (![popoverController isPopoverVisible]) {


    [popoverController presentPopoverFromBarButtonItem:barButton3 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    //[popoverController presentPopoverFromRect:CGRectMake(10, 10, 20, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];        

}
else {
    [popoverController dismissPopoverAnimated:NO];
}


}

I have a SplitviewController with multiple possible Detailviews (Webviews, Tableviews, regular UIViews).

As an example, I have a NavigationController on top, then navigate through some tables.

Finally I show some Content, lets say a UIWebview. I rotate the iPad to portrait, and in the toolbar I add a Button from which the popOverController is displayed.

On Buttonclick I say:

if (!popoverController) {

if (self.view.window != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:  [appDelegateiPad naviPad]];

popoverController.delegate = self;

 }
}

Here, I instantiate a PopOverController and the Content is the left part of the splitview, from the point I left off. All is nice.

But when I rotate, I get this warning:

CoreAnimation: ignoring exception: Popovers cannot be presented from a view which does not have a window.

And on the screen the popOverController reappears with empty content (black translucent I would say) but I don't know why, since I dismissed it and there cant be another instance since I only create one on buttonclick.

This has been driving me crazy for days.

ANY(!) help is appreciated!

-(void) showPopOver:(id) sender {




NSLog(@"showing popover?");

if (!popoverController) {

    if (self.view.window != nil) {
        popoverController = [[UIPopoverController alloc] initWithContentViewController:[appDelegateiPad naviPad]];
        //RootViewController *r = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle: nil];
        //  popoverController = [[UIPopoverController alloc] initWithContentViewController:r];
        //popoverController.popoverContentSize = CGSizeMake(320, 800);
        //popoverController.delegate = self;
    }
 }


if (![popoverController isPopoverVisible]) {


    [popoverController presentPopoverFromBarButtonItem:barButton3 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    //[popoverController presentPopoverFromRect:CGRectMake(10, 10, 20, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];        

}
else {
    [popoverController dismissPopoverAnimated:NO];
}


}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文