after dismissing viewController, popViewController won't work

343 views Asked by At

I have stucked in scenario: look at this picture: enter image description here

I have soundPlayerVC as childeViewController of pageContentVC.

soundPlayerVC Present mail modalViewController:

- (IBAction)emailStory:(id)sender {

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    Anecdote *anecdote = (Anecdote *)story;
    [picker setSubject:anecdote.name];
    [picker setMessageBody:[SearchHandler removeMarkupsFromPageText:anecdote.detail] isHTML:NO];
    [self.parentViewController presentViewController:picker animated:YES completion:nil];
}

    #pragma mark - mail compose delegates
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [controller dismissViewControllerAnimated:YES completion:nil];
}

but when I tap on backButton, popViewController doesn't work, because navigationController has been emptied!!

HOW THIS HAPPENED? could someone explain?

1

There are 1 answers

0
Hashem Aboonajmi On

I found the solution: that was because of I didn't popViewController in the right viewController.

pageContentVC is child of bookRootVC so bookRootVC is responsible of removing pageContnetVC from navigationController Stack.

I created a protocol and added a delegate property pageContnetVC and assigned bookRootVC as delegate of pageContnetVC

protocol DismissViewControllerDelegate <NSObject>
- (void)popViewController;
@end

bookRootVC implement the protocol:

#pragma mark pop view controller delegate
- (void)popViewController
{
    [self.navigationController popViewControllerAnimated:YES];
}

in viewDidLoad

 self.pageViewController.delegate = self;

and finally backButton in pageContentVC call its delegate to remove this view from navigationController.

thats all!