我使用自定义 UIButton 创建了 UIToolbar 作为 xib 中 BarButtonItem 的子项。我在我的应用程序中使用工具栏作为导航栏。我需要从按钮显示弹出框,因此我在按钮操作上创建弹出框,如下所示:
- (void)showSelectSourcePopover:(UIButton *)sender
{
UIViewController* popoverContent = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 400)];
popoverView.backgroundColor = [UIColor blueColor];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 400);
UIPopoverController * popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//[popoverController presentPopoverFromBarButtonItem:sender
// permittedArrowDirections:UIPopoverArrowDirectionUp
// animated:YES];
CGRect rect = [sender bounds];
[popoverController presentPopoverFromRect:rect inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
但它崩溃没有任何错误。我尝试了 presentPopoverFromBarButtonItem 函数,但它也崩溃了。