我希望通过 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];
Thanks!
从 UIViewController 执行 PopOver,而不是在 UICollectionViewCell 中。所以,使用委托来控制。
//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];
}
}
以及适合您的代码:https://github.com/lequysang/TestPopOver https://github.com/lequysang/TestPopOver
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)