OGeek|极客世界-中国程序员成长平台

标题: ios 将 Objective-c 数据从第二个 View Controller 发送到第一个 View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:53
标题: ios 将 Objective-c 数据从第二个 View Controller 发送到第一个 View Controller

我有 2 个 View Controller 。第一个是 UIview Controller ,第二个是 TableView Controller 。 在选择第二个 View Controller 的行后,我想将数据第二个( TableView Controller )发送到第一个(uiview Controller )。 为此,我编写了一个委托(delegate)协议(protocol)。 但是我的委托(delegate)协议(protocol)不起作用...... 我发现了问题。我正在创建的第二个 View Controller 的对象。

address = [[second_viewcontroller alloc] init];
address.delegate = self;

与 second_viewcontroller View Controller 页面的 self 不同。 如何使这两个相同。

self = [[second_viewcontroller alloc] init];



Best Answer-推荐答案


您的问题我的委托(delegate)协议(protocol)不起作用...我发现了问题。我正在创建的第二个 View Controller 的对象。地址=[[second_viewcontroller alloc]init];地址.delegate=自己;与 second_viewcontroller View Controller 页面的 self 不同。

很明显,您创建 second_viewcontroller 对象的方式是不对的。

您必须从 ViewController Storyboard标识符创建对象。 首先将 Storyboard ID 从 Storyboard 提供给 ViewController。按照此步骤提供 Storyboard ID。

  1. 在 Storyboard 中选择特定的 ViewController。
  2. 转到 IdentityInspector。
  3. 在 IdentityInspector 下,有标识部分,并在“Storyboard ID”字段中添加 Storyboard ID。

创建 ViewController 对象的语法。

Second_viewController *aVC = [self.storyboard instantiateViewControllerWithIdentifier"Second_viewController"];
aVC.delegate = self;

关于ios 将 Objective-c 数据从第二个 View Controller 发送到第一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38965511/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4