I want a UINavigationController-based menu system to show up in a UIPopover, that is 'popping over' a CCLayer, in my iPad app. So far, I can get a UINavigationController to show up in a UIPopover, but it only shows the root view in the stack - I can't successfully push another view controller on the stack. When I do push another view controller on the stack, the method [UINavController visibleViewController] returns the view controller I just pushed, but that view controller is not visible on the screen. I am stuck - the code I have works in when 'popped over' a UIViewController, but doesn't seem to work in the CCLayer-based app I have built. I could use any help in understanding what might be going on and / or how I could approach getting things to work correctly.
Here is the relevant code:
First, I create a UIButton programatically in an object that is a CCLayer, then I add is as a subview to the openGLView:
CGRect launchMenuButtonRect = CGRectMake(973.0, 2.0, 50.0, 50.0);
launchMenuButton = [[UIButton alloc] initWithFrame:launchMenuButtonRect];
launchMenuButton.backgroundColor = [UIColor redColor];
launchMenuButton.enabled = YES;
[launchMenuButton addTarget:self action:@selector(launchMenuButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[[[CCDirector sharedDirector] openGLView] addSubview:launchMenuButton];
When that button from the above code is pressed, the 'launchMenuButtonPressed' method is fired, and it displays a UIPopover, that has a UINavigationController with my desired first view controller:
- (void)launchMenuButtonPressed {
NSLog(@"registered touch for the launch menu button");
//create the viewcontrollers in the navigation stack
contentMenuScreen = [[ContentMenuViewController alloc] init];
MainMenuViewController *mainMenuScreen = [[MainMenuViewController alloc] init];
menuNavController = [[UINavigationController alloc] initWithRootViewController:mainMenuScreen];
mainMenuScreen.delegate = self;
UIPopoverController *popMenu = [[UIPopoverController alloc] initWithContentViewController:mainMenuScreen];
[popMenu setPopoverContentSize:CGSizeMake(350.0, 450.0)];
[popMenu presentPopoverFromRect:launchMenuButton.frame inView:[[CCDirector sharedDirector] openGLView] permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
That first view controller (called mainMenuScreen) shows up just fine as well as registers touches correctly. That view controller responds to a button touch and should push another view controller on to the navigation stack:
- (IBAction) tweetContentButtonPressed
{
NSLog(@"tweetContentButtonPressed");
//[[self delegate] switchToTweetContentMenu];
ContentMenuViewController *contentMenuScreen = [[ContentMenuViewController alloc] init];
[self.navigationController pushViewController:contentMenuScreen animated:YES];
NSLog(@"visible view controller is %@", [self.navigationController visibleViewController]);
}
At this point, the above NSLog line returns 'contentMenuScreen x(some hex address)'. However, the first view controller is still visible and responding to touch. The second view controller (called contentMenuScreen) is not visible.
As part of my troubleshooting effort, I created delegate methods for the CCLayer object to receive the touches of the MainMenuViewController and respond by pushing a ContentMenuViewController on the menuNavController stack, but that had the same exact effect. I also built a prototype app that had a barButtonItem in a standard UIViewController (not a CCLayer), and that works fine - the second view controller is pushed on to the stack and is visible, responds to touch, etc.
I am stumped, and really want to get this working. I saw the technique is an app called KoiPondHD on the iPad if you would like a reference on how it should operate.