显示来自UIButton的popover

时间:2012-09-11 18:47:00

标签: objective-c uipopovercontroller

我使用自定义UIButton创建了UIToolbar,作为xib中BarButtonItem的子代。我在我的应用程序中使用工具栏作为导航栏。 我需要从按钮显示popover,所以我在按钮操作上创建popover,如下所示:

     - (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函数,但它也崩溃了。

0 个答案:

没有答案