In Xcode 5.0.2 I've created an app for iPhone with a navigation controller and 3 further view controllers (here fullscreen):
I'd like the LoginViewController (with the "Login" title in the above screenshot) be the delegate for the navigation controller, so that its method
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
is called - so I have added the following code to its viewDidLoad
:
UINavigationController *nc = self.navigationController;
[nc setDelegate:self];
This works, but I wonder if setting the delegate for the navigation controller is also possible in the Interface Builder?
I've tried ctrl-dragging from the yellow cube sign of the navigation controller to the LoginViewController scene and vice versa - but I'm only offered a popup to create a segue...
EDIT: this answer might be outdated as of Dec 2015. This answer is probably more accurate for XCode 6 and newer.
Long long ago, before storyboards existed, setting delegates was possible using outlets (although I don't remember if it was possible for UINavigationController, I only remember that I did it with UITableView). You would just right-click on Navigation Controller and drag from the outlet to the target:
However, according to this answer, it's not possible anymore. You can do it programatically in viewDidLoad
as you did, or using prepareForSegue:
.