从UICollectionViewCell呈现UIPopoverController [英] Presenting a UIPopoverController from UICollectionViewCell

查看:79
本文介绍了从UICollectionViewCell呈现UIPopoverController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从UICollectionViewCell上的按钮呈现UIPopoverController。

I'm looking to present a UIPopoverController from a button on a UICollectionViewCell.

到目前为止,所有内容都已创建,但弹出窗口不可见。

So far, everything is created ok, but the popover isn't visible.

这有什么特别的方法吗?

Is there a special way of doing this?

如果我从集合视图单元格以外的任何其他位置显示代码,则代码有效。

The code works if I display it from anything else other than a collection view cell.

以下代码在UICollectionViewCell子类中。

The following code is in the UICollectionViewCell subclass.

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];

谢谢!

推荐答案

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

Perform PopOver from UIViewController, not in UICollectionViewCell. So, use delegate to control.

//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

这篇关于从UICollectionViewCell呈现UIPopoverController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆