UIPopoverController View from UICollectionViewCell

I want to present a UIPopoverController using a button on a UICollectionViewCell.

So far, everything is created fine, but the popover is not displayed.

Is there a special way to do this?

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

The following code is in a subclass of 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]; 

Thanks!

+6
source share
2 answers

Run a PopOver from a UIViewController, not a UICollectionViewCell. So use a delegate to manage.

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

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

And the code for you: https://github.com/lequysang/TestPopOver

+5
source

change inView to collectionView

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

+3
source

All Articles