我试图在 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"op" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
[popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
解决方案
现在效果很好:
Pop *controller = [[Pop alloc] initWithNibName"op" 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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |