Calling popToRootViewControllerAnimated after UIImagePicker has completed or canceled? (iPhone target C)

I am trying to implement live camera functionality in my iPhone app and am running into problems. Basically the way of structuring is this: I provide a UINavigationController where the user can navigate to the image with the table view and (if selected) the detail view.

They can then press a button and take a new photo using the camera. Ideally, what should happen is that after shooting or canceling, they go back to the navigation root where the images are displayed again. To do this, I implement the UIImagePickerController delegate in my main detail view controller.

It's all implemented just fine except for the last bit - I can access the photo, etc., but when I try to go back to that first list - using popToRootViewControllerAnimated - I get an error EXC_BAD_ACCESS

. Here is the quoted version of the relevant code ( didFinishPickingMediaWithInfo

... imagePickerControllerDidCancel

works the same):

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    // Do some image processing stuff here...

    [picker dismissModalViewControllerAnimated:YES];
    [picker release];

    [self.navigationController popToRootViewControllerAnimated:YES];    
}

      

Commenting that the last line makes it work, but then it just goes back to the detail view with the original photo, not the list.

Anyone?

Update : A detail I forgot to mention earlier ... Pop does work to a certain extent. The camera is selected and returns to the list. However, when the app dies (the selected table cell is still blue from where the user tapped earlier). I also tried using popViewControllerAnimated

instead of the same result.

+2


source to share


3 answers


Hope it's not too late for you. I ran into the same issue today and banged my head against my MBP for about 30 minutes before I started getting a little creative.

I found two ways to make this work. Nothing is intuitive, but here you go. Basically, it looks like the problem could be caused by the fact that you are calling "pop" on the navigationController before the firing animation has finished.

I found that if I set the boolean animation on firing to "NO" then it worked.

eg.

[picker dismissModalViewControllerAnimated:**NO**];

      

Another option is to create a second method that actually calls the "pop" function, and calls it using a timer with a short offset. Just to start the firing animation.



eg.

-(void)popMe {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    [picker release];

    [self performSelector:@selector(popMe) withObject:nil afterDelay:0.1];   
}

      

This time worked for me, you might have to tweak.

Hope it helps!

  • Andrew
+4


source


You are the problem here [picker rejectModelViewController] and [picker picker] I believe ... You don't need to release the picker, it is released to u when u fires the modal view controller which I believe (which you are doing right from what I can s ee) ... Either that, or it has a reference count of 0 and shouldn't be an issue, somehow I remember doing something like this and it crashing because I released the collector ... Also I noticed you have you is there a picker that disables the modal view manager, are you sure this is what you are trying to do? not [self rejectModalViewController] or which ViewController ever you clicked on this view?



+1


source


Answer:
Use this: [self.navigationController rejectModalViewControllerAnimated: YES]; instead of [picker removeModalViewControllerAnimated: YES];
Now you can remove this line from your code: [self.navigationController popToRootViewControllerAnimated: YES];

+1


source







All Articles