【问题标题】:Presenting a UIPopoverController from UICollectionViewCell从 UICollectionViewCell 呈现一个 UIPopoverController
【发布时间】:2013-01-16 18:56:47
【问题描述】:

我希望通过 UICollectionViewCell 上的按钮呈现 UIPopoverController。

到目前为止,一切都创建好了,但弹出框不可见。

有没有一种特殊的方法可以做到这一点?

如果我从集合视图单元格以外的任何其他地方显示代码,该代码就可以工作。

以下代码在 UICollectionViewCell 子类中。

if (_infoPopover == nil) {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    GameInfoViewController *gameInfoVC = (GameInfoViewController *)[storyboard instantiateViewControllerWithIdentifier:@"GameInfoViewController_ID"];

    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:gameInfoVC];
    _infoPopover = popover;
    [gameInfoVC setGameNameString:_gameNameLabel.attributedText];
}

[_infoPopover presentPopoverFromRect:_infoButton.frame inView:self permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

谢谢!

【问题讨论】:

  • 请在您尝试显示弹出框的位置显示代码。您可能使用了错误的矩形。

标签: xcode ios6 uipopovercontroller uicollectionview uicollectionviewcell


【解决方案1】:

从 UIViewController 执行 PopOver,而不是在 UICollectionViewCell 中。所以,使用委托来控制。

//Cell.m
-(void)popOVerClick:(UIButton *)button{
    [[self delegate] didPopOverClickInCell:self];
}

实现协议

//ViewController
    -(void)didPopOverClickInCell:(MyCell *)cell{
    if ([self.flipsidePopoverController isPopoverVisible]) {
        [self.flipsidePopoverController dismissPopoverAnimated:YES];
    } else {

        FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
        controller.label.text = cell.title;
        controller.delegate = self;

        self.flipsidePopoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
        [self.flipsidePopoverController presentPopoverFromRect:cell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
}

还有给你的代码:https://github.com/lequysang/TestPopOver

【讨论】:

    【解决方案2】:

    将 inView 更改为 collectionView

    [_infoPopover presentPopoverFromRect:_infoButton.frame inView:self.collectionView allowedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    【讨论】:

      猜你喜欢
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      相关资源
      最近更新 更多