Anth0
Anth0

Reputation: 3052

How to use a UIImagePickerController with UINavigationController

I've browsed the different similar questions here but couldn't find anything useful for my problem. What I'm struggling with is quite simple but I can't figure it out.

I'm using Xcode 4.6.2 and Storyboarding. Here is the storyboard: enter image description here

Here is the workflow I'd like to have:

Problem is the Edit document view does not have the navigation bar even if I try to set the property self.navigationBarHidden = NO; This seems normal to me though since I've presented the views modally but how to do it then?

I tried pushing my cameraVC from the tableVC but I get an error saying that stacking 2 navigationControllers is prohibited (since cameraVC subclass of UIImagePickerController subclass of UINavigationController). It seems that my only option is to present the cameraVC modally but then I don't know how to present the Edit document VC with its navigation bar.

EDIT: Having a navigation bar in the cameraVC is not optimal but is acceptable if this is the only way of doing it.

Upvotes: 0

Views: 1031

Answers (1)

micantox
micantox

Reputation: 5616

It would appear that the best solution is to use an unwind segue!

In summary:

1)In the tableVC create a method such as

- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
{
    NSLog(@"Rolled back");
}

2)Create an unwind segue for your previewDocumentVC and give it a unique ID such as "unwindFromPreview", connecting it to the unwindToThisViewController IBAction. Check this answer I gave in the past for the detailed steps on how to achieve this (steps 2 and 3).

3)Create a prepareForSegue method in your previewDocumentVC where you set some tableVC BOOL property, such as

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"unwindFromPreview"]) {
        ((TableVC*)segue.destinationViewController).shouldTransitionToEditDocVC = YES;
    }
}

4) In your tableVC's ViewWillAppear method you then check the shouldTransitionToEditDocVC and if it is set to YES you perform the segue to the editDocVC.

I hope this helps!

Upvotes: 1

Related Questions