I am trying to convert my app to use a navigation controller. It uses the EAGLView from the Xcode GL ES startup project to render its graphics. I am trying to add it to the navigation controller hierarchy. The EAGLView is currently constructed by the nib, so the first thing I do is remove it from the window so it doesn't appear twice. When I try to add the view to the view controller, instead of rendering the view, it just displays #FF00FF in the EAGLView's rectangle. [UPDATE] When the same code is run on the device, the GL view flickers between black and the last thing that was rendered in OpenGL, so this is probably a problem with the GL view. I'll see if I can't pin down something more specific based on that info.
The button and navigation controller bar appear and behave correctly.
If I set rootController.view = rootView;
and uncomment those two lines of code, the view displays red as it should.
Here is the relevant code from the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[glView removeFromSuperview];
// construct the root view controller and view
UIViewController* rootController = [[UIViewController alloc] init];
//UIView* rootView = [[UIView alloc] initWithFrame:window.frame];
//rootView.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
rootController.title = @"Root";
rootController.view = glView;
UIButton* pushSubviewButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
pushSubviewButton.frame = CGRectMake(50, 50, 150, 37);
[pushSubviewButton setTitle:@"Push Subview" forState:UIControlStateNormal];
[pushSubviewButton addTarget:self action:@selector(pushSubview:) forControlEvents:UIControlEventTouchUpInside];
[rootController.view addSubview:pushSubviewButton];
navigationController = [[UINavigationController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
[window addSubview:navigationController.view];
[glView startAnimation];
return YES;
}
- (void) pushSubview:(id)sender
{
UIViewController* secondController = [[[UIViewController alloc] init] autorelease];
UIView* secondView = [[[UIView alloc] initWithFrame:window.frame] autorelease];
secondView.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:1];
secondController.title = @"Second";
secondController.view = secondView;
[navigationController pushViewController:secondController animated:YES];
}