Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you manage the events in a UINavigationController view to switch views?

I have a UINavigationController w/ three views and associated buttons in the UINavigationBar for each view. Since I am new to XCode I'm trying to understand where to put the event handling code for managing the switch between views.

View A (root)

Goto View B (button)

View B

Back (button) Gotto View C (button)

View C

Back (button)

I see how to capture the event when "Goto View B" is clicked, but since that button is created in View A it does not have access to the UINavigationController to switch views.

Any samples or links to additional info appreciated.

like image 291
ChrisP Avatar asked Nov 29 '25 15:11

ChrisP


1 Answers

If I understand your question correctly, have a look at:

UINavigationControllerDelegate: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationControllerDelegate_Protocol/Reference/Reference.html

UINavigationBarDelegate: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationBarDelegate_Protocol/Reference/Reference.html

If you are simply trying to push a new view using the navigationController, it is as simple as this (in your GoToViewB button/action):

YourNewViewController *yourNewViewController = [[YourNewViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:yourNewViewController animated:YES];
[yourNewViewController release];

Now you should be in your newViewController, which will have a back button to return to the previous view. You can use the same logic as above to go to the next view etc. If you want to pop a controller programatically, you can use:

[self.navigationController popViewControllerAnimated:YES];
like image 81
Rog Avatar answered Dec 01 '25 06:12

Rog