6

Szukam przedstawić UIPopoverController z przycisku na UICollectionViewCell.Przedstawianie UIPopoverController z UICollectionViewCell

Do tej pory wszystko zostało utworzone w porządku, ale popover nie jest widoczny.

Czy istnieje specjalny sposób na zrobienie tego?

Kod działa, jeśli wyświetlam go z dowolnego innego obiektu niż komórka widoku kolekcji.

Następujący kod znajduje się w podklasie 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]; 

Dzięki!

+0

Proszę pokazać kod, w którym próbujesz wyświetlić popover. Prawdopodobnie używasz niewłaściwego recta. – jrturton

+0

Zaktualizowany, patrz wyżej. –

Odpowiedz

5

Wykonaj PopOver z UIViewController, a nie UICollectionViewCell. Skorzystaj więc z opcji delegowania do kontroli.

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

wdrożyć 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]; 
    } 
} 

a kod dla Ciebie: https://github.com/lequysang/TestPopOver

3

zmienić INview do CollectionView

[_infoPopover presentPopoverFromRect: _infoButton.frame INview: self.collectionView permittedArrowDirections: UIPopoverArrowDirectionAny animowane: TAK];

Powiązane problemy