Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top