从MainViewController发送值到ContainerViewController?

时间:2015-03-05 09:05:22

标签: ios segue uicontainerview

我正在开发一个应用程序,我想从MainViewController向ContainerViewController发送值。我已经将MainVC的委托添加到Container(A)中,我定义了一个发送值的方法。但是这种方法不起作用。我认为我对prepareForSegue的使用是错误的。委托是否可用于使用不同方法的两个视图之间的双向通信? 我添加了图像来描述我的情况。

感谢您的帮助。

这是我的MainVC代码块;

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
    if ([segue.identifier isEqualToString:@"layersViewSegue"]) {
    [ (LayersViewController *)segue.destinationViewController setDelegate:self];


}
else if ([segue.identifier isEqualToString:@"addLayerSegue"]) {
    [ (AddLayerViewController *)segue.destinationViewController setDelegate:self];


}
}

容器A代码块

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"layersViewSegue"]) {
    [ (ViewController *)segue.destinationViewController setDelegate:self];

}
}

enter image description here

1 个答案:

答案 0 :(得分:0)

这样的事情:

YourDestinationController.h //容器

@property (strong, nonatomic) NSString *assignableString // any object/variable

MainViewController.m

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"yourSegueIdentifier"])
    {
        YourDestinationController *yourDestinationController = (YourDestinationController*)segue.destinationViewController;
        yourDestinationController.assignableString = /* your string */;
    }
}