[英]Pop to particular controller on iOS | Objective-c
I have the following code to push new ViewControllers. 我有以下代码来推送新的ViewController。
- (IBAction)btnEditPressed:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"contactListViewController"];
[self parentShowViewController:controller sender:sender];
}
- (void)parentShowViewController:(UIViewController *)controller sender:(id)sender {
if ([self isIOS7]) {
// En iOS7 no existe el método showViewController
[self.navigationController pushViewController:controller animated:YES];
} else {
//[self.navigationController pushViewController:controller animated:YES];
[super showViewController:controller sender:sender];
}
}
Now I have the following scenario: I have 3 ViewControllers called A,B,C. 现在,我有以下情形:我有3个名为A,B,C的ViewController。
A->B->C If press back button I want to back from C to A A-> B-> C如果按后退按钮,我想从C退回到A
Try something like this 试试这个
If you want go to Controller A from controller C on Controller C create custom back button and set the action of it, and put the following code. 如果要从控制器C上的控制器C转到控制器A,请创建自定义后退按钮并设置其操作,然后输入以下代码。
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
This is only work if you know that Controller A is your first Controller in Navigation. 仅当您知道控制器A是导航中的第一个控制器时,此方法才有效。
If you don't know the order of viewController try this one 如果您不知道viewController的顺序,请尝试这一步
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[ViewControllerA class]]) {
[self.navigationController popToViewController:VC animated:Yes];
}
}
And to add a custom button go to this link 并添加自定义按钮,请转到此链接
Hope this will help you. 希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.