6

UICollectionViewCell'de bir düğmeden UIPopoverController sunmak istiyorum.UICollectionViewCell'den bir UIPopoverController sunmak

Şimdiye kadar her şey yolunda, ancak popover görünür değil.

Bunu yapmanın özel bir yolu var mı?

Bir koleksiyon görünümü hücreden başka bir şeyden görüntülediğimde bu kod çalışır.

Aşağıdaki kod UICollectionViewCell alt sınıfındadır.

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

Teşekkürler!

+0

Lütfen pop-up'ı görüntülemeye çalıştığınız kodu gösterin. Muhtemelen yanlış rekt kullanıyorsun. – jrturton

+0

Güncelleme, yukarı bakın. –

cevap

5

UICollectionViewCell'de değil, UIViewController'dan PopOver gerçekleştirin. Yani, denetlemek için temsilci kullanın.

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

protokolünü

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

Ve sizin için kod uygulamak: _infoButton.frame Inview: self.collectionView permittedArrowDirections: CollectionView'ın

[_infoPopover presentPopoverFromRect için https://github.com/lequysang/TestPopOver

3

değişim InView UIPopoverArrowDirectionAny animasyonlu: EVET];