在解除viewController之后,popViewController将无法正常工作

时间:2014-01-06 08:23:22

标签: uinavigationcontroller childviewcontroller parentviewcontroller popviewcontrolleranimated

我陷入了困境: 看这张图片: enter image description here

我有soundPlayerVC作为pageContentVC的childeViewController。

soundPlayerVC当前邮件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];
}

但是当我点击backButton时,popViewController不起作用,因为navigationController已被清空!!

这是怎么发生的? 有人可以解释一下吗?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案: 那是因为我没有在右侧viewController中使用popViewController。

pageContentVCbookRootVC的孩子,因此bookRootVC负责从navigationController堆栈中删除pageContnetVC

我创建了一个协议并添加了委托属性pageContnetVC并指定bookRootVC作为pageContnetVC

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

bookRootVC实施协议:

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

中的

 self.pageViewController.delegate = self;

最后在pageContentVC中的backButton调用其委托从navigationController中删除此视图。

这就是全部!