有没有办法可以导航到ViewController,它是UInavigationcontroller堆栈的中间位置

时间:2016-12-08 08:21:38

标签: ios objective-c uinavigationcontroller

我有Collection View Controller PatientList - >选择单元格导航到PatientdetailView - >点击按钮导航到startDignosisView。这是导航控制器堆栈。现在,从患者列表中,我有一个导航到AddpatientView的按钮“ADD”,我必须导航到StartdignosisView而不会干扰导航堆栈。我该怎么做?

5 个答案:

答案 0 :(得分:0)

if let viewControllers = self.navigationController?.viewControllers {
    var newStack: [UIViewController] = []
    for viewController in viewControllers {
        newStack.append(viewController)
        if viewController is StartdignosisView {
            break
        }
    }
    self.navigationController?.viewControllers = newStack
}

答案 1 :(得分:0)

尝试这样:

   some *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"some identifier you add to a vc in the storyboard"];
   [self.navigationController pushViewController:vc animated:YES];

只需将标识符设置为该视图控制器的故事板即可。

答案 2 :(得分:0)

for (UIViewController *controller in self.navigationController.viewControllers)
{
    if ([controller isKindOfClass:[NeededViewController class]])
    {
        [self.navigationController popToViewController:controller
                                          animated:YES];
        break;
    }
}

答案 3 :(得分:0)

如果您不使用情节提要,请按照以下步骤操作:

看看你是否添加患者然后直接导航到StartDignosisVC然后你将无法弹出到PatientDetailVC

你可以从这两个中做任何一个:

首先:

尝试展示您的AddPatientVC,添加新内容然后将其关闭并按照旧的堆栈路径进行操作。

<强>第二 一个ADD按钮操作实例化您的AddpatientView,如下所示:

AddPatientVC *obj = [storyboard instantiateViewControllerWithIdentifier:@"AddPatientVC"];

同样导航到StartdignosisView并设置一个来自AddPatientVC的标志:

 StartDignosisVC *obj = [storyboard instantiateViewControllerWithIdentifier:@"StartDignosisVC"];
    obj.isFromAddPatientView = true

当你从StartDignosisVC按Back按钮时,检查你是否来自AddPatientVC直接将其弹出到患者列表。

如果您使用的是故事板,那么您可以执行以下操作,请参阅随附的屏幕截图: enter image description here

答案 4 :(得分:0)

感谢Mayank的回答:以下代码适用于我的案例。  [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];