Ios 将字符串从第二个视图控制器传递到第一个控制器

Ios 将字符串从第二个视图控制器传递到第一个控制器,ios,objective-c,delegates,protocols,Ios,Objective C,Delegates,Protocols,我正在尝试将字符串从第二个VC发送到第一个VC。我已经将委托分配给了第一个VC,并在第二个VC中给出了协议,但是当第二个VC发送一些数据时,我没有看到第一个VC中的方法被调用 代码 第一个VC FirstViewController.h SecondViewController.h 非常感谢您提供的任何帮助。也许您只是忘了将第二个ViewController.delegate分配给self 1-在第一个viewController中,在按下secondViewController之前,使用该se

我正在尝试将字符串从第二个VC发送到第一个VC。我已经将委托分配给了第一个VC,并在第二个VC中给出了协议,但是当第二个VC发送一些数据时,我没有看到第一个VC中的方法被调用

代码

第一个VC

FirstViewController.h

SecondViewController.h


非常感谢您提供的任何帮助。

也许您只是忘了将第二个ViewController.delegate分配给self

1-在第一个viewController中,在按下secondViewController之前,使用该secondViewController实例执行以下操作:

secondViewController.delegate = self;

我无法发表评论,因此如果这不起作用,请告诉我或共享更多代码。

也许您只是忘记将secondViewController.delegate分配给self

1-在第一个viewController中,在按下secondViewController之前,使用该secondViewController实例执行以下操作:

secondViewController.delegate = self;
我无法发表评论,因此如果这不起作用,请告诉我或分享更多代码。

您忘了这么做

SecondViewcontroller *vc;

vc.delegate=self;
在第一次查看控制器时,您忘记了执行以下操作

SecondViewcontroller *vc;

vc.delegate=self;

在第一视图控制器上

当您从一个VC导航到第二个VC时,您可以设置代理

SecondViewcontroller *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewcontroller"];
secondVC.delegate = self;
[self.navigationController pushViewController:secondVC animated:YES];

这段代码写在FirstViewController上。希望它能帮助您。

当您从一个VC导航到第二个VC时,您可以设置代理

SecondViewcontroller *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewcontroller"];
secondVC.delegate = self;
[self.navigationController pushViewController:secondVC animated:YES];

这段代码写在FirstViewController上。希望对您有所帮助。

您是否为
SecondViewController
delegate
属性指定了值?@rmaddy您是指字符串参数吗?是的,我做到了。。!如果您谈论的是其他内容,那么不,我没有。不,我谈论的是
委托
属性。如果不设置它,就不能调用它的
printString:
方法。我不明白@rmaddy,你能告诉我该怎么做吗?为什么..?你不知道你自己的
委托
属性在你的
SecondViewController
中是什么吗?您需要为其分配一个值。
SecondViewController
delegate
属性是否分配了一个值?@rmaddy您是指字符串参数吗?是的,我做到了。。!如果您谈论的是其他内容,那么不,我没有。不,我谈论的是
委托
属性。如果不设置它,就不能调用它的
printString:
方法。我不明白@rmaddy,你能告诉我该怎么做吗?为什么..?你不知道你自己的
委托
属性在你的
SecondViewController
中是什么吗?你需要给它赋值。
SecondViewcontroller *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewcontroller"];
secondVC.delegate = self;
[self.navigationController pushViewController:secondVC animated:YES];