Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UINavigationController返回到多个步骤_Ios_Cocoa Touch_Uinavigationcontroller - Fatal编程技术网

Ios UINavigationController返回到多个步骤

Ios UINavigationController返回到多个步骤,ios,cocoa-touch,uinavigationcontroller,Ios,Cocoa Touch,Uinavigationcontroller,是否可以在UINavigationController中弹出多个viewcontroller?假设我想后退两步。是的,你可以通过做类似的事情来实现 //Your navigation controller UINavigationController *nav; //Get the view controller that is 2 step behind UIViewController *controller = [nav.viewControllers objectAtIndex:nav

是否可以在UINavigationController中弹出多个viewcontroller?假设我想后退两步。

是的,你可以通过做类似的事情来实现

//Your navigation controller
UINavigationController *nav;

//Get the view controller that is 2 step behind
UIViewController *controller = [nav.viewControllers objectAtIndex:nav.viewControllers.count - 2];

//Go to that controller
[nav popToViewController:controller animated:YES];
Swift

在swift中,Omar提出的相同解决方案为:

// Get the previous Controller.
let targetController: UIViewController = navigationController!.viewControllers[navigationController!.viewControllers.count - 2]

// And go to that Controller
navigationController?.popToViewController(targetController, animated: true)
在我的情况下,我需要备份2个控制器,因此,我必须在堆栈中进行第3次备份。我真正的解决办法是:

// obtaining origin controller
let controller: UIViewController = navigationController!.viewControllers[navigationController!.viewControllers.count - 2]

// If was the expected controller (An enroll action)
if controller is CreateChatViewController {

    // I get the previous controller from it, in this case, the 3rd back in stack
    let newControllerTarget = navigationController!.viewControllers[navigationController!.viewControllers.count - 3]

    // And finally sends back to desired controller
    navigationController?.popToViewController(newControllerTarget, animated: true)
}