PopViewControllerAnimated无法正常工作。没有参考呼叫VC

时间:2014-03-30 23:36:18

标签: objective-c uiviewcontroller presentviewcontroller

我有UITabBarViewController包含4个单独的ViewControllers。每个VC在UIBarButtonItem上都有一个NavigationBar,可以带您进入" postPage"。您可以使用此代码进入帖子页面,该代码显示嵌入式NavigationController

- (void)postInvoked:(UIBarButtonItem *)sender
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *postPage = [storyboard instantiateViewControllerWithIdentifier: @"postPageLead"];
    [self presentViewController:postPage animated:YES completion:nil];
}

然后在PostViewController.m中,当用户点击IBAction名为"后退"

时,我会触发UIBarButtonItem
- (IBAction)backOnPost:(UIBarButtonItem *)sender
{
    [self.parentViewController.navigationController popViewControllerAnimated:YES];
}

这不起作用。请记住,一旦到达邮局,就不会记住呼叫VC。如何遍历原始调用ViewController?(如何引用调用者,popViewControllerAnimated是必需的?)

2 个答案:

答案 0 :(得分:8)

取而代之的是它,它应该可以正常工作。

- (IBAction)backOnPost:(UIBarButtonItem *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

答案 1 :(得分:2)

我使用以下方法修复了它:

- (IBAction)backOnPost:(UIBarButtonItem *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}