views:

42

answers:

1

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  A: 

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.

Darryl H. Thomas
I see now that I should have used "navController" instead of "navigationController". You've got this one anyway ;)One quick follow up question though. What is the memory management rule for * msel? Should I release it at some point? If so, where?
whitehawk
This is most likely the answer.
TechZen
It would be good to ask this as a separate question so that others can discover it, but the convention is that any retained outlet/property should be released in your dealloc method and if the outlet/property is set during load (either programmatically or via nib file), you should also set the property to nil (or release the ivar and set it to nil) in the viewDidUnload method.
Darryl H. Thomas
Read the second paragraph of the discussion section of the -viewDidUnload method for a clearer description of my answer: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/viewDidUnload
Darryl H. Thomas
Noted. Thank you!
whitehawk