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开发者_StackOverflow社区 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.
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];
精彩评论