How to pop from one view controller to another view controller

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

                break;
            }
        }

You can't pop to a new view controller (like you do with your secondViewController example).

When using a UINavigationController you

Add Controller to the stack with:

[self.navigationController pushViewController:<yournewViewController> animated:YES];

Pop to the previous one with :

[self.navigationController popViewControllerAnimated:YES];

Pop to a previous controller in the stack (Must have been pushed before) :

[self.navigationController popToViewController:<ViewControllerToPopTo> animated:YES];

Go back to the root Controller with

[self.navigationController popToRootViewControllerAnimated:YES];