【问题标题】:Send value from MainViewController to ContainerViewController?将值从 MainViewController 发送到 ContainerViewController?
【发布时间】:2015-03-05 09:05:22
【问题描述】:

我正在开发一个应用程序,我想将值从 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];

}
}

【问题讨论】:

    标签: ios segue uicontainerview


    【解决方案1】:

    类似这样的:

    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 */;
        }
    }
    

    【讨论】:

    • 感谢您的回答。我将V值从B容器发送到MainVC,而不是从MainVC到容器A.我尝试在选择ContainerView时调用PrepareForsegue,但我收到这个问题“'容器视图中有意外的子视图。也许嵌入的Segue已经触发一次或者SubView以编程方式添加? “我该怎么办?
    • 从来没有遇到过这个问题......真的很难通过提供的信息来解决问题。
    猜你喜欢
    • 1970-01-01
    • 2013-09-05
    • 2013-03-29
    • 1970-01-01
    • 2013-04-27
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多