Ryan
Ryan

Reputation: 4884

Is there any way to remove specific view controller from UINavigationController's stack?

I want to remove a viewController from UINavigationController's stack.

is it possible? I found that UINavigationController.viewControllers is a type of NSArray, and it means I can't change.

I also know that I can change the stack(NSArray) with popViewController() or pushViewController(). How is it possible?

Can I change a specific viewController in UINavigationController to other viewController? or is there a way just remove a viewController from the stack?

Upvotes: 2

Views: 3107

Answers (1)

nielsbot
nielsbot

Reputation: 16031

This will do what you want:

NSMutableArray * viewControllers = [ <<navController>>.viewControllers mutableCopy ]
[ viewControllers removeObject:<<viewControllerToRemove>> ] ;
navController.viewControllers = viewControllers ;

But this sounds "funny" to me--Can I ask why you want to implement this behavior?

Upvotes: 5

Related Questions