Enmanuel G
Enmanuel G

Reputation: 156

Difference between Pop and Push a ViewController

I'd like to know if there's any difference between pushing and poping a UIViewController.

Upvotes: 1

Views: 2883

Answers (2)

Andrew
Andrew

Reputation: 3892

Think of the navigation stack as a stack of plates. You start with one plate. If you put another plate on top of the first plate, thats pushing. You can do that over and over if you want. You can even put the same plate on top of itself. Then when you want to go back one class, that is take one plate off the stack, you are poping. You can do that until theres only one plate left.

Upvotes: 0

Chris Cooper
Chris Cooper

Reputation: 17564

They do opposite things.

You push to add it to the stack of visible UIViewControllers, and pop it to remove it.

The terminology comes from the stack data-structure. The idea is that you "push", or place, objects on the top of the stack, and each object can't be removed until all the objects above it have been removed ("popped").

You can read more about stacks here.

Upvotes: 5

Related Questions