我试图在 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];