views:

1988

answers:

1

I have an app where I display the photo chooser (UIImagePickerController) but after the user dismisses it only single touches are working. And I think I know the root of the issue, but I don't know how to solve it... Before I show the modal dialog the stack during a touch is as follows:

...
#3  0x00074de0 in -[EAGLView touchesBegan:withEvent:] at EAGLView.m:289
#4  0x30910f33 in -[UIWindow _sendTouchesForEvent:]
...

But after showing and then removing the modal dialog the stack has these two mysterious forwardMethod2 calls:

...
#3  0x00074de0 in -[EAGLView touchesBegan:withEvent:] at EAGLView.m:289
#4  0x3098dc95 in forwardMethod2
#5  0x3098dc95 in forwardMethod2
#6  0x30910f33 in -[UIWindow _sendTouchesForEvent:]
...

Here is the code I use to display and remove the UIImagePickerController: Notes: 1. pickerViewController is a member of this class that extends UIViewController) 2. Director is from Cocos2D and contains only a single view attached directly in the root window called openGLView, which is why I made a UIViewController to house my image picker.

-(void)choosePhoto: (id)sender{
    UIImagePickerController *imagePickerController = pickerViewController.imagePickerController;
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.allowsImageEditing = YES;

    UIView *theView = [[Director sharedDirector] openGLView];
    UIView *pickerViewControllerView = pickerViewController.view;
    [theView addSubview:pickerViewControllerView];
    [pickerViewController presentModalViewController:imagePickerController animated:YES];
}

And the code to dismiss the dialog:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePickerController
{
    // Dismiss the image selection
    [pickerViewController dismissModalViewControllerAnimated:YES];
    [pickerViewController.view removeFromSuperview];

    // HERE... IS THERE MORE WORK TO BE DONE TO COMPLETELY REMOVE THE PICKER VIEW????
}

There must be something I'm missing in cleaning up the picker view... Help is greatly appreciated :)

+2  A: 

After investigating the view hierarchy from the root window down I have found that after dismissing the Photo chooser that my viewController's view was getting added as a child under a UITransitionView so the solution is to remove the superview of my viewController's view instead:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePickerController
{
    // Dismiss the image selection
    [pickerViewController dismissModalViewControllerAnimated:YES];
    [pickerViewController.view.superview removeFromSuperview];
}
CJ Hanson