0

I have the following code to push new ViewControllers.

- (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.

A->B->C If press back button I want to back from C to A

1 Answer 1

4

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.

 [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.

If you don't know the order of viewController try this one

    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.

Sign up to request clarification or add additional context in comments.

1 Comment

If you don't know how to add custom button in navigationbar, let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.