gpt4 book ai didi

ios - 无法从没有窗口的 View 中显示弹出窗口 - presentPopoverFromBarButtonItem

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:53 25 4
gpt4 key购买 nike

我试图在点击 UIBarButtonItem 时显示一个 UIPopover。我收到此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController presentPopoverFromBarButtonItem:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'

这是我的代码:

Pop *controller;
UIPopoverController *popoverController;
controller = [[Pop alloc] initWithNibName:@"Pop" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];

[popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

解决方案

现在效果很好:

Pop *controller = [[Pop alloc] initWithNibName:@"Pop" bundle:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
popoverController.delegate=self;

[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

最佳答案

弹出窗口必须显示在另一个 View Controller 之上,不能让弹出窗口漂浮在半空中。只需创建一个 View Controller 以在其之上呈现 View Controller 。

UIViewController *vc = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];

然后创建并显示您的弹出窗口。

关于ios - 无法从没有窗口的 View 中显示弹出窗口 - presentPopoverFromBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18552441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com