来自 UICollectionView 的弹出视图导致放松 [英] Popover view from UICollectionView causing unwind

查看:22
本文介绍了来自 UICollectionView 的弹出视图导致放松的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UICollectionView 中显示了一个数据矩阵(玩家).当用户触摸单元格时,我希望播放器的详细信息显示在弹出视图中.我早些时候问过这个问题并让它起作用.但从那以后,一个奇怪的问题出现了.

I have a matrix of data (players) displayed in a UICollectionView. I want details on a player to display in a popover view when the user touches a cell. I asked this question earlier and got it to work. But since then, a strange problem developed.

当我触摸一个单元格时,弹出框出现,但主视图展开两个屏幕(!?)并且应用程序崩溃并出现以下错误:'由于未捕获的异常'NSGenericException'而终止应用程序,原因:'-[UIPopoverController dealloc] 在弹出窗口仍然可见时达到.'

When I touch a cell, the popover appears, but the main view unwinds two screens (!?) and the app crashes with this error: 'Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'

playerDataView 内置在故事板中.我已经在其头文件中将 playerDataView 控制器和弹出视图控制器声明为集合视图的属性:

The playerDataView is built in the storyboard. I've declared both the playerDataView controller and the popover view controller as properties of the collection view in its header file:

@property (strong, nonatomic) UIPopoverController *playerDataPopover;
@property (strong, nonatomic) SWSPlayerDataViewController *playerDataView;

这是实例化弹出框的代码:

Here's the code that instantiates the popover:

- (IBAction)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 || indexPath.section == 0) {  // Ignores user selecting row or column headers that I've placed in the collection view data
        return;
    }
    [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
    CGRect anchorRect = [collectionView layoutAttributesForItemAtIndexPath:indexPath].frame;
    self.playerDataView = [self.storyboard instantiateViewControllerWithIdentifier:@"playerDataView"];
    self.playerDataView.player = self.players[indexPath.section][indexPath.row]; // Sets player data in popover view.
    self.playerDataPopover = [[UIPopoverController alloc] initWithContentViewController:self.playerDataView];
    [self.playerDataPopover presentPopoverFromRect:anchorRect inView:self.collectionView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

如果从集合视图中展开,我可以理解为什么会出现该错误,但我无法弄清楚为什么会发生展开.有什么想法吗?

I can understand why I would get that error if there is an unwind from the collection view, but I can't figure out why the unwind is occurring. Any ideas?

推荐答案

您可以通过在视图控制器的 dealloc 方法中解除弹出框来避免弹出框dealloc 异常.

You can avoid the popover dealloc exception by dismissing your popover in your view controller's dealloc method.

您的 unwind segue 可能已在故事板中设置,您只需找到并删除它.您可以尝试在 prepareForSegue: 上设置断点,以查看传入的 segue 对象或那里的堆栈跟踪是否为您提供任何线索.

Your unwind segue is probably set up in your storyboard, you just need to find and remove it. You can try setting a breakpoint on prepareForSegue: to see if either the segue object passed in or the stack trace there gives you any clues.

这篇关于来自 UICollectionView 的弹出视图导致放松的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆