我试图在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];
答案 0 :(得分:1)
必须在另一个视图控制器的顶部显示弹出窗口,你不能在半空中浮动弹出窗口。只需创建一个视图控制器,即可将视图控制器呈现在。
之上UIViewController *vc = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
然后创建并展示你的popover。