Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between self.navigationController and delegate.navigationController

i can use

MyFirstAppDelegate *delegate = (MyFirstAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navigationController popViewControllerAnimated:YES];

or

[self.navigationController popViewControllerAnimated:YES];

So what is the difference between both ?

Please answer me ......

Thanks in advance..

like image 616
S.P. Avatar asked Jan 22 '26 01:01

S.P.


2 Answers

You use the first form when you are accessing the navigation controller from an object that is not a view controller controlled by the navigation controller. That form accesses the navigation controller via the object that owns it i.e. the application delegate. Since the application delegate can be easily called from anywhere in the program, it is a good place to park things than any object might need a reference to.

You use the second form from an view controller that is controlled by the navigation controllers. It will only work from a view controller that has been previously pushed onto the stack.

like image 64
TechZen Avatar answered Jan 23 '26 15:01

TechZen


I assume that you have one navigation controller the code is executing in a view controller that is on that navigation stack.

If so, then they both access the same navigation controller and there is no difference between them.

Typically, you would use the second form.

like image 33
gerry3 Avatar answered Jan 23 '26 15:01

gerry3