Popover view from UICollectionView causing unwind

时光毁灭记忆、已成空白 提交于 2019-12-12 00:55:33

问题


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.

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.'

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/22120224/popover-view-from-uicollectionview-causing-unwind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!