在 UIPopoverController 中导航

Navigation inside a UIPopoverController

我有一个包含 table 视图的 UIPopoverController。这个弹出控制器显示得很好,我已经很好地设置了委托 didSelectRowAtIndexPath

现在,我想根据单击的 table 项目将某些过渡到 "detail view controller"。然后在目标视图上,它有像 pushViewController 这样的后退按钮,但效果不佳。它不会导航到详细视图控制器。这是我的 didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    DetailSummaryViewController *detailVC = [[DetailSummaryViewController alloc] initWithNibName:@"DetailSummaryViewController" bundle:nil];
    [self.navigationController pushViewController:detailVC animated:YES];
}

这是我的弹窗方法

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    CalendarCell *cell = (CalendarCell *)[collectionView cellForItemAtIndexPath:indexPath];

    UIPopoverController *popC = [[UIPopoverController alloc] initWithContentViewController:[SummaryViewController new]];
    [popC setPopoverContentSize:CGSizeMake(320, 400)];
    [self setPop:popC];

    [[self pop] presentPopoverFromRect:[cell frame]
                                inView:collectionView
              permittedArrowDirections:UIPopoverArrowDirectionAny
                              animated:YES];
}

那些导航不会工作,但如果我 NSLog-ing 选择的索引它工作得很好。是否有我遗漏的设置导航的步骤?

创建 UIPopoverController 时,不应在 UIPopoverController 中设置 MyViewController,而应设置 UINavigationController

    UINavigationController *insidePopoverNavigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
    popoverController = [[UIPopoverController alloc] initWithContentViewController:insidePopoverNavigationController];
    ...... 
    [popoverController presentPopoverFromRect:... etc];

您的弹出框控制器中没有 导航控制器,因此方法 self.navigationController pushViewController 将不起作用。试试下面这个:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    CalendarCell *cell = (CalendarCell *)[collectionView cellForItemAtIndexPath:indexPath];

    UINavigationController *insidePopoverNavigationController = [[UINavigationController alloc] initWithRootViewController:[SummaryViewController new]];

    UIPopoverController *popC = [[UIPopoverController alloc] initWithContentViewController:insidePopoverNavigationController];
    [popC setPopoverContentSize:CGSizeMake(320, 400)];
    [self setPop:popC];

    [[self pop] presentPopoverFromRect:[cell frame]
                                inView:collectionView
              permittedArrowDirections:UIPopoverArrowDirectionAny
                              animated:YES];
}

其他致谢:Raica Dumitru Cristian