objective-c - 将数据传输回原始 View

标签 objective-c ios xcode data-transfer

所以我能够将数据从第一个 View 传输到第二个 View ,如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if ([segue.identifier isEqualToString:@"Check Mark Segue"])
      {
        NSLog(@"Transfering Data");
        AutoRenewDrop *controller = segue.destinationViewController;
        controller.transferData = self.renewDate.text;
      }
}

但是,当用户点击完成并且 transferData 工作正常但 renewDate.text 没有改变时,我尝试将新值传输回 renewDate.text 。这是我用来传回数据的代码:
-(IBAction)done:(UIStoryboardSegue *)segue {

[self.navigationController popViewControllerAnimated:YES];
AddR *add = [[AddR alloc] init];
add.renewDate.text = transferData;

}

有人可以告诉我如何解决这个问题吗?

最佳答案

您需要将包含第一个 View 引用的属性添加到第二个 View 中:

@interface AutoRenewDrop
@property(weak, nonatomic) AddR *callerView;
@end

然后在第二个 View 的 done 方法中,您可以在调用者 View 中更新变量:
-(IBAction)done:(UIStoryboardSegue *)segue {
[self.navigationController popViewControllerAnimated:YES];
callerView.renewDate.text = transferData;
}

当然,当您实例化第二个 View 时,您必须以这种方式设置引用:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if ([segue.identifier isEqualToString:@"Check Mark Segue"])
      {
        NSLog(@"Transfering Data");
        AutoRenewDrop *controller = segue.destinationViewController;
        controller.transferData = self.renewDate.text;
        controller.callerView = self; //Here, you are passing the reference to this View
      }
}

关于objective-c - 将数据传输回原始 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13209835/

相关文章:

ios - UITableView 和 UITableViewHeader 在旋转和调整大小后发生冲突

ios - 如何在 iOS 中使 UIAlertView 变大?

ios - 如何找出核心数据模型iOS中特定属性索引的值

ios - 从vimeo URL Objective-C中提取Vimeo视频ID

ios - 显示最近的问题 clang : error: linker command failed with exit code 1 (use -v to see invocation)?

iphone - 如何在 TabBar 中正确集成 InAppSettingsKit 与 Storyboard?

ios - objc_autoreleaseReturnValue 是什么意思?

ios - 如何设置 UISwitch 边框颜色?

ios - 按键排序基于 NSDictionary 的 UITableView

ios - 在 XCODE 7.2 中加载文件时出错并崩溃