whitehawk
whitehawk

Reputation: 2425

Calling pushViewController on a UINavigationController does nothing (no crash)

I have a UINavigationController as one of the views inside a tab bar control. It looks fine, and I have a UIBarButtonItem that is supposed to load a subview. I have the button wired up to an IBAction that calls pushViewController but when I do this nothing happens. It doesn't crash or anything.. it just doesn't do anything. I've tried: using different view controllers as the subview (no luck). Does anybody have any suggestions? Here is my code:

Header file:

#import <UIKit/UIKit.h>
#import "FSSettings.h"
#import "MeasureSelector.h"
#import "Dashboard.h"

@interface DashboardNavigationController : UIViewController {
 IBOutlet UINavigationController  *navController;
 IBOutlet UINavigationBar   *navBar;
 IBOutlet UIBarButtonItem   *measureButton;
}

@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@property (nonatomic, retain) IBOutlet UINavigationBar   *navBar;
@property (nonatomic, retain) IBOutlet UIBarButtonItem   *measureButton;

- (IBAction) showMeasureScreen:(id)sender;

@end

And the .m file containing the action:

// Displays the measure screen
- (IBAction) showMeasureScreen:(id)sender
{
 NSLog(@"Loaded measure screen");
 MeasureSelector *msel = [[MeasureSelector alloc] initWithNibName:@"MeasureSelector" bundle:nil];

 [[self navigationController] pushViewController:msel animated:YES];
 NSLog(@"Done.");
}

When I click the button nothing happens (but I do see the log messages). I can do this over and over with no ill effects, however.

Upvotes: 1

Views: 2636

Answers (1)

Darryl H. Thomas
Darryl H. Thomas

Reputation: 1021

The navigationController property of UIViewController refers to the nav controller of which the UIViewController is part of the hierarchy. If I understand the scenario correctly, DashboardNavigationController manages the view that is the container for the UINavigationController, so it makes sense that this property would be nil.

Use the outlet you created to access the nav controller from outside of the nav controller's hierarchy.

Upvotes: 2

Related Questions