Reputation: 29
What is the SetViewController in IOS which case developer preferred?
what is difference between setViewController and PushViewController in IOS?
Please help me
Thanks.
Upvotes: 0
Views: 4761
Reputation: 27428
First thing it is not SetViewController
but it is setViewControllers
because it's sets array of view controller
.
You can only set view controller to navigation controller
or tabbar controller
like wise you can pushviewcontroller
only in navigation controller
not in tabbar controller
Now lets understand the concept of navigation stack
:
For example you have one navigation controller says it nav
.
It hasn't any objects (View controllers).
Now for example you have array of three view controllers like A,B & C
and you set that array to you navigation controller
something like,
[self.navigationController setViewControllers:viewControllerArr];
Then your navigation stack become like
A -> B -> C (top of stack)
Now you push one view controller to same navigation stack, let's say it D
something like,
[self.navigationController pushViewController:D animated:YES];
Then your navigation stack like become,
A -> B -> C -> D (top of stack)
Now if you pop one view controller something like,
[self.navigationController popViewControllerAnimated:YES];
Then it pop top of stack and then your stack looks something like,
`A -> B -> C (top of stack)`
Again pop one then,
`A -> B (top of stack)`
So, basically main difference between set and push view controller is, when you set view controllers, you are setting array means multiple array. So, we can say that setViewController
is initialization of navigation controller with initial controller (initialization of navigation stack)
where push or pop is adding or removing view controller to or from navigation stack.
Hope this will help :)
Upvotes: 7
Reputation: 14122
A navigation controller is used to manage a stack of view controllers. You can "push" controllers onto the stack one at a time (this is what you would do almost all of the time) or you can "set" a stack containing multiple controllers in one go. Read the manual.
Upvotes: 0