获取对容器视图视图的引用 [英] Getting reference to the view of a container view
问题描述
我是iOS App Development的新手。我连接了一个tableview控制器,这样当我选择其中一行时,我会使用didSelectRowAtIndexPath获得另一个UIViewController。我在这个UIViewController中有一个容器视图,它显示(当然是)调用didSelectRowAtIndexPath的行的索引。我想用segue做这个,但问题是我不知道如何获得对使用容器视图形成的视图控制器的引用。我知道您可以在prepareForSegue中使用segue.destinationViewController获取目标View Controller,但是如何获取对由于容器视图而将加载的视图控制器的引用。我正在为iOS 6构建应用程序。此外,我还使用了Storyboard作为UI。谢谢
I am new to iOS App Development. I have connected a tableview controller such that when I select one of the rows I get another UIViewController using didSelectRowAtIndexPath. I have a container view inside this UIViewController which displays (say for the time being) index of the row on which didSelectRowAtIndexPath was called. I want to do this using a segue, but the problem is I don't know how to get a reference to the view controller which is formed by using the container view. I know you can get the destination View Controller using segue.destinationViewController in the prepareForSegue but how do I get a reference to view controller that will be loaded because of the container view. I am building the app for iOS 6. Also I have used Storyboard for the UIs. Thanks
这个问题主要归结为如何获得对UIViewController-2的引用正在由UIVonConiner-1内部的UIContainerView指出。通过选择一行UITableViewController来触发UIViewController-1
This question basically comes down to how to get a reference to the UIViewController-2 that is being pointed by the UIContainerView which is inside the UIViewController-1. The UIViewController-1 is triggered by selecting a row of UITableViewController
UITableViewController(选择要给出的行)---> UIViewController-1其中包含.... ContainerView - - > UIViewController-2(与ContainerView关联的ViewController)。
UITableViewController (selecting a row to give)---> UIViewController-1 which contains....ContainerView --->UIViewController-2(ViewController associated with ContainerView) .
推荐答案
好的,让我们想象一下这个场景:
Ok, let's imagine this scenario:
让我们假设您要更新第二个视图控制器的子节点上的标签,其中模型数据支持您在表格视图中点击的单元格。
And let's assume you want to update the label on that "child of second view controller" with the model data backing the cell you tapped on the table view.
你能做的是:
-
从第一个场景到第二个场景的segue是一个唯一的标识符(例如
Detail
),在第二个视图控制器中定义一个属性,以接收传递给它的值(例如someStringValue
),并写一个<传递值的code> prepareForSegue ,例如:
Give the segue from the first scene to the second one a unique identifier (e.g.
Detail
), define a property in that second view controller to receive the value being passed to it (e.g.someStringValue
), and write aprepareForSegue
that passes the value, e.g.:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Detail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
[segue.destinationViewController setSomeStringValue:self.objects[indexPath.row]];
}
}
对你的embed segue重复这个过程,即,给你的嵌入segue自己的唯一标识符(例如嵌入
)并在第二视图控制器的子视图视图控制器中创建一个属性,以接收传递给它的值(例如 someStringValue
),并在第二个视图控制器中有一个 prepareForSegue
,它将值传递给其子视图控制器,例如:
Repeat this process for your embed segue, namely, give your embed segue its own unique identifier (e.g. Embed
) and create a property in that "child of second view controller" view controller to receive the value passed to it (e.g. someStringValue
), and have a prepareForSegue
in the second view controller that will pass the value along to its child view controller, e.g.:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Embed"])
{
[segue.destinationViewController setSomeStringValue:self.someStringValue];
}
}
这篇关于获取对容器视图视图的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!