【问题标题】:Navigation inside a UIPopoverControllerUIPopoverController 内的导航
【发布时间】:2016-02-13 15:17:50
【问题描述】:

我有一个由表格视图组成的UIPopoverController。这个弹出式控制器显示得很好,我已经设置了委托didSelectRowAtIndexPath 就好了。

现在,我想根据单击的表项进行一些过渡到“详细视图控制器”。然后在目标视图上,它有类似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 选择的索引它工作得很好。是否有一些设置导航的步骤我错过了?

【问题讨论】:

  • 下面的答案(Raica)是解决它的方法。

标签: ios objective-c ipad uinavigationcontroller uipopovercontroller


【解决方案1】:

当你创建 UIPopoverController 时,而不是在 UIPopoverController 中设置 MyViewController,你应该设置一个 UINavigationController

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

【讨论】:

    【解决方案2】:

    您的弹出框控制器中没有导航控制器,因此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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多