Navigation Controller Issue: View not loading after pushViewControlleranimated called
Folks, New to iPhone development so I greatly appreciate your help. I have been looking at documentation and trying many things to get my navigation controller functionality working but can't.
Here's the situation. I have an app delegate which sets its root controller to be a navigation controller:
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.mainViewController.navController;
[self.window makeKeyAndVisible];
return YES;
}
The navigation controller is a property of the mainviewcontroller because I intend to take the user to a map view (associated with a mapviewcontroller) only when they select an item in a tableview owned by mainviewcontroller. I can't yet think of a graceful way to notify the appdelegate about a table row selection, hence I am trying to handle this in the mainviewcontroller.
In the mainviewcontroller init function:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Custom initialization
navController = [[UINavigationController alloc] initWithRootViewController:self];
mapController = [[MapViewController alloc] init];
}
return self;
}
In mainview control开发者_运维百科ler, when the user selects an item from the tableview, I call:
[self.navController pushViewController:mapController animated:YES];
The view associated with my mapviewcontroller never appears. Any ideas what's going on?
Thanks
Add this
[self.window addSubview:self.mainViewController.navController.view];
Before
[self.window makeKeyAndVisible];
精彩评论