6

私は、UICollectionViewCellのボタンからUIPopoverControllerを提示することを検討しています。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]; 

ありがとうございます!

+0

ポップオーバーを表示しようとするコードを表示してください。あなたはおそらく間違った矩形を使用しています。 – jrturton

+0

更新済み、上記を参照してください。 –

答えて

5

UICollectionViewCellではなく、PopViewをUIViewControllerから実行します。したがって、委任を使用して制御します。

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

そして、あなたのためのコードを実装します。_infoButton.frameののInView:self.collectionViewのpermittedArrowDirections:UIPopoverArrowDirectionAny collectionView

[_infoPopover presentPopoverFromRectへhttps://github.com/lequysang/TestPopOver

3

変更のInViewをアニメーション:はい];

関連する問題