Alaa Eldin
Alaa Eldin

Reputation: 2268

UINavigationController pushViewController

the view controller that is pushed onto the stack cannot be an instance of tab bar controller and it must not already be on the navigation stack.

I want to know how could I discover if the view controller that I'm about to push onto the stack is already in stack.

Upvotes: 1

Views: 2391

Answers (4)

Ankit Srivastava
Ankit Srivastava

Reputation: 12405

Try this and let me know if it works.

for (UIViewController* controller in [self.navigationController viewControllers]) {
    if ([controller isKindOfClass:[MapViewViewController class]])
    {
        NSLog(@"Cool");
    }

}

Upvotes: 3

Ayaz Alavi
Ayaz Alavi

Reputation: 4835

are you looking for

[self.navigationController popToViewController:controller animated:YES];

Use the self.navigationController.viewControllers array to reference the controller that's already on the nav controller's stack.

Upvotes: 1

smparkes
smparkes

Reputation: 14063

Check if its navigationController property is nil.

Upvotes: 3

utsabiem
utsabiem

Reputation: 920

You can use flags. Set a flag when you push the viewcontroller first time. Reset it if you pop to this view controller. Check the flag value before pushing. If set, it is already in stack, so don't push again. else, not in stack, so push it.

Upvotes: 0

Related Questions