如何在uicollectionview原型单元格内的按钮上显示弹出窗口

时间:2013-07-05 10:51:37

标签: ios objective-c uicollectionview popover

我为单元格创建了一个UpcomingCell.h和.m。在按钮的点击方法中,我尝试了这个

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
//    cameraSystemMenu =   [mainStoryboard instantiateViewControllerWithIdentifier:@"CameraSystemMenuViewController"];

    UIView *anchor = sender;
    UIViewController *viewControllerForPopover =
    [storyboard instantiateViewControllerWithIdentifier:@"yourIdentifier"];

    self.popover = [[UIPopoverController alloc]
               initWithContentViewController:viewControllerForPopover];
    [self.popover presentPopoverFromRect:anchor.frame
                             inView:anchor.superview
           permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

我也试过这个

self.popoverContent = [[PopOverViewController alloc]init];


UIView *popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];

[popoverView setBackgroundColor:[UIColor purpleColor]];



self.popoverContent.view = popoverView;

self.popoverContent.contentSizeForViewInPopover = CGSizeMake(200, 300);

UIPopoverController *contactPopover =[[UIPopoverController alloc] initWithContentViewController:self.popoverContent];

[contactPopover presentPopoverFromRect:self.remindButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES ];

[contactPopover setDelegate:self];

和stackoverflow上的无数其他popover示例,我无法让它工作。

两个例子都崩溃了。第一个崩溃

传入此方法的rect必须具有非零的宽度和高度。这将是未来版本中的例外

1 个答案:

答案 0 :(得分:0)

第二个崩溃,因为UIPopoverController需要是属性或实例变量,否则它将在方法的末尾解除分配,因为显示它的View将不会保留它