繁体   English   中英

prepareForSegue通过引用目标视图控制器传递值

[英]prepareForSegue is passing value by Reference to Destination view Controller

我在我的一个应用程序中使用情节提要,并且在prepareForSegue方法中将属性从SourceViewController传递到DestinationViewController时,传递的属性是通过引用传递的,而不是通过值传递的。 如果用户在弄乱值并轻按后退,则在Destination View Controller中给我造成麻烦,然后我在SourceViewController中得到了我不想要的更新值。

请查看以下内容以获取有关此问题的更多信息

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{if([[segue identifier] isEqualToString:@"DestinationView"])
    {
        DestinationViewController  *destinationViewController = [segue destinationViewController];
        [destinationViewController setActivity:activity];
        //Here the value of activity is passed by reference. I have verified the same by checking the address of activity variable in Variable pane of Xcode in Source and destination view controller
}

现在,我不确定在上述情况下如何只传递值而不传递引用。

尝试使用它的副本

    [destinationViewController setActivity:[activity copy]];

如果需要,实现其委托copywithZone

- (id)copyWithZone:(NSZone *)zone

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM