在UIPopoverController中导航

我有一个包含表视图的UIPopoverController 。 这popup控制器显示很好,我已经设置委托didSelectRowAtIndexPath就好了。

现在,我想根据点击的表项进行一些“细节视图控制器”的转换。 然后在目的地视图上,它有一个像pushViewController后退button,但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]; } 

这是我的popup式方法

 - (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的选定的索引它很好地工作。 有没有设置导航的一些步骤,我错过了?

你没有在你的self.navigationController pushViewController 控制器中有一个导航控制器 ,所以方法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

当您创buildUIPopoverController时,不要在UIPopoverController中设置MyViewController,而应该设置一个UINavigationController

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