1
votes

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.

1
I should also note that I in the viewDidLoad of the subview I put a log statement and that log is never hit. - whitehawk
Also, if I do this: NSLog(@"%@", [self navigationController]); It outputs "null" - whitehawk
To clarify, there is a distinction between views and view controllers, and this appears to have been muddled in some of your naming conventions. Lets start with a basic question: What is the superclass of MeasureSelector? - Darryl H. Thomas
You've defined navController as a property. Is this also nil? - Darryl H. Thomas

1 Answers

2
votes

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.