从UICollectionView的popup视图导致放松
我有一个显示在UICollectionView
的数据matrix(玩家)。 当用户触摸一个单元格时,我需要在弹窗视图中显示一个玩家的细节。 我早些时候问过这个问题,然后才开始工作。 但从那时起,一个奇怪的问题就出现了。
当我触摸一个单元格,popup窗口出现,但主视图展开两个屏幕(!?)和应用程序崩溃与此错误: 终止应用程序由于未捕获exception'NSGenericException',原因:' – [UIPopoverController dealloc] popover仍然可见。
playerDataView内置在故事板中。 我已经在其头文件中声明了playerDataView控制器和popover视图控制器作为集合视图的属性:
@property (strong, nonatomic) UIPopoverController *playerDataPopover; @property (strong, nonatomic) SWSPlayerDataViewController *playerDataView;
以下是实例化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]; }
我可以理解,为什么我会得到这个错误,如果从收集视图放松,但我不明白为什么放松正在发生。 有任何想法吗?
你可以通过在视图控制器的dealloc方法中closures你的popover来避免popover deallocexception。
你可以在你的故事板中设置你的放松时间,你只需要find并删除它。 您可以尝试在prepareForSegue:
上设置一个断点prepareForSegue:
查看传入的segue对象或堆栈跟踪是否给出了任何线索。