xcode - 从 UICollectionViewCell 呈现一个 UIPopoverController

标签 xcode ios6 uipopovercontroller uicollectionview uicollectionviewcell

我正在寻找从 UICollectionViewCell 上的按钮呈现 UIPopoverController。

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

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

如果我从 Collection View 单元格以外的任何其他地方显示代码,则该代码有效。

以下代码位于 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];

谢谢!

最佳答案

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

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

执行协议(protocol)
//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

关于xcode - 从 UICollectionViewCell 呈现一个 UIPopoverController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14365654/

相关文章:

iphone - iOS6 不显示 MKAnnotationView 标注

ios - AppDelegate 的 ViewController 内的 Preform 函数

ipad - 弹出窗口中的导航 Controller

ios - 级联弹出框 : User Friendliness vs Guidelines

objective-c - 弹出窗口和桌面 View 透明

objective-c - Objective C 中的 Sqlite 数据库插入语句

ios - 如何在聚焦时调整 UISearchController.searchBar 的大小问题?

ios - 如何实现PSCollectionView?

ios - XCode 9.1 链接器错误与来自 Unity 5.6.4 项目的 facebook sdk 7.11 中的位码相关

crash - 选择器 View 上的断言失败