-4

When we click back button in navigation controller, it'll automatically pops the view controller and goes back to the previous view controller.. could anyone tell me how it's works.. where is the code for that action in xcode.

veeramani
  • 107
  • 1
  • 1
  • 7

3 Answers3

2

The code which does all of that is handled in Apple's UINavigationController class. You don't get to see this code.

If you want to change the behavior of Apple's classes they sometimes delegate responsibility for some of the actions they perform, or sometimes just provide information that something is going to happen.

For example if your class becomes the delegate of UINavigationController it will send you two messages:

– navigationController:willShowViewController:animated:
– navigationController:didShowViewController:animated:
jackslash
  • 8,550
  • 45
  • 56
  • Thanks jack. But we can see the UINavigationController Class functions right..? – veeramani Feb 03 '12 at 07:05
  • Yup. The UINavigationController tells you what functions it can perform. In objective-c these are declared in a .h file while the code goes in a .m file. In Xcode go to file>Open Quickly and type in UINavigationController.h. Alternatively you can look in the documentation to see what it does. However you do not get to see that actual code. – jackslash Feb 03 '12 at 08:39
1

I dont know what you exactly mean by "how it works"..but what happens is the view controllers are placed in a stack (RootController which is the Navigation controller) and when you press "back" button it simply pops the top most controller in the stack and you are back from where you came.Hope it helps..!!

Suny
  • 1,175
  • 1
  • 10
  • 27
  • when we press back button it pops the viewcontroller. but there must be code for this action right..?. Where'll be that code exists..? – veeramani Feb 03 '12 at 07:01
1

Are you looking this?

 [self.navigationController popViewControllerAnimated:YES];
Simone Pistecchia
  • 2,746
  • 3
  • 18
  • 30
  • no simone.. when we press back button it pops the viewcontroller. but there must be code for this action right..?. Where'll be that code exists..? – veeramani Feb 03 '12 at 07:05