Search code examples
iphoneipaduitableviewuinavigationcontrolleruipopovercontroller

How to nest a navigationController inside of a UIPopOverController?


There are actually three views at play. My homeView, which is where I launch the picker from, which sets the StudyPickerController view as root to a navController, which is then presented inside of the popOverController. Then from within the StudyPickerController view, I need to push to the ScreenPickerController, a different view completely.

I have a UIPopOverController that is displaying the contents of a view that is a tableView. I would like to be able to push a new view with a viewController inside of this view, but as I will discuss, it is really close, but it just won't push!

So from my homeView, when the button is pushed, an action is called and this code is run:

self.studyPicker = [[[StudyPickerController alloc] initWithStudyArray:self.studyArray ViewNum:butto.tag] autorelease];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.studyPicker];   

_studyPicker.delegate = self;
self.studyPickerPopover = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];               

[self.studyPickerPopover presentPopoverFromRect:CGRectMake(120,45, 10,10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

And this works pretty well! The popOverController displays the contents of my StudyPickerController without any problems. I get the feeling that I am indeed getting access to my navigationController because the frame of the popOverController has a bar at the top, instead of just being a thin border, it has a navigationBar.

So now when I want to select a row in this view, I would like to push to a new view, also with a tableView, with my navigationController. This is the code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSArray * array = [_studyArray objectAtIndex:indexPath.row];

    ScreenPickerController * picker = [[ScreenPickerController alloc] init];
    picker.seriesGUID = array;
    picker.viewNumber = viewNumber;

    [self.navigationController pushViewController:picker animated:YES];
}

It seems to me that this should be working! But alas, I press a row, and it highlights, and nothing happens.

I've been working on this all day, so it very well could be that I am just missing something, but I don't know what it is. Any help is appreciated


Solution

  • It seems there are two classes involved here: your homeView class and the StudyPickerController. I'm guessing the tableView:didSelectRowAtIndexPath: method would be in the homeView class?

    In that case, self.navigationController is trying to access the navigation controller that homeView is in, not the navigation controller you put into the popover. Since homeView isn't even in a navigation controller, the accessor returns nil.

    Instead, you will want to use something like [self.studyPicker.navigationController pushViewController:picker animated:YES];.