views:

341

answers:

2

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..

+3  A: 

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.

gerry3
Thank you gerry.....
Sijo
If you found this answer useful, please consider "accepting" it. Thanks.
gerry3
+2  A: 

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. This form access the navigation controller via the object that owns it, 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.

TechZen
Thank you..My Doubt is fully cleared...Once again thank you TechZen
Sijo