如何将参数传递给导航控制器内的弹出视图控制器 [英] How to pass parameters to a popover view controller inside a navigation controller

查看:114
本文介绍了如何将参数传递给导航控制器内的弹出视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在detailviewcontroller的导航栏中有一个带有splitview和右边栏按钮的iPad应用程序。

I have an iPad app with splitview and a right bar button in the navigation bar of the detailviewcontroller.

此按钮调用由导航控制器和两个导航控制器组成的弹出窗口表格视图。
,如下图所示

This button calls a popover constituted of a navigation controller and two table views. as shown in the following picture

由于故事板在图片上很小,我添加了一些解释。
White控制器是detailViewController(splitviewcontroller的右侧),它位于导航控制器内。白色视图右侧的三个视图是从左到右:navigationController,firstTableView,secondTableView。

As the storyboard is small on the picture I add some explanation. The White controller is the detailViewController (right hand side of the splitviewcontroller), which is inside a navigtion controller. The three views on the right side of the white view are from left to right : navigationController, firstTableView, secondTableView.

我的问题是我需要将参数传递给第一个表格视图,以正确配置它。

My problem is that I need to pass parameters to the first table view to configure it correctly.

当视图控制器共享同一个导航控制器时,我会这样做。

I use to do it like that when view controller were sharing the same navigation controller.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"popoverButtonSegue"]){
        MyPopoverFirstTableViewController *popoverFirstTVC = [[MyPopoverFirstTableViewController alloc] init];

        popoverFirstTVC = segue.destinationViewController;
        popoverFirstTVC.property1 = aProperty1;
        popoverFirstTVC.property2 = aProperty2;
    }
}

我的问题是我在这样做时收到错误,因为目标控制器不是我的popoverFirstTableViewController,但NavigationController和导航控制器当然没有property1和property2。

My Problem is that I get an error doing this because the destination controller is not my popoverFirstTableViewController but the NavigationController and the navigation controller of course does not haver "property1" and "property2".

也许这是一个基本问题,但我是卡在这里。

Perhaps it's a basic question but I am stuck here.

如何通过分配我在表中导航控制器时定义的一些属性来配置我的tableview?

How do I do to configure my tableview by assigning some of its properties I have defined when this table is inside a navigation controller ?

推荐答案

所有的功劳都属于@Michael Kernahan,但只要他不发布它作为答案,我会把它作为一个跟进来写对于寻找相同答案的人来说。

All the credit belongs to @Michael Kernahan, but as long as he don't post it as an answer I'll write it as a follow up for people looking for the same answer.

在我的情况下问题是我正在分配目标控制器,这是导航控制器

In my case the problem was that I am assigning the destination controller which is the navigation controller

popoverFirstTVC = segue.destinationViewController; 

我应该做的是访问该导航控制器的topViewController。

what I should do is to access the topViewController of that navigation controller.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"popoverButtonSegue"]){
        MyPopoverFirstTableViewController *popoverFirstTVC = (MyPopoverFirstTableViewController *)((UINavigationController *) segue.destinationViewController).topViewController;

        popoverFirstTVC.property1 = aProperty1;
        popoverFirstTVC.property2 = aProperty2;
}

这篇关于如何将参数传递给导航控制器内的弹出视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆