[英]Pass data between view controllers
我对Objective C和xCode还是很陌生,所以请原谅我。
我在情节提要中设置了两个视图控制器,即时消息使用以下代码移至另一个:
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController * viewController = [storyBoard instantiateViewControllerWithIdentifier:@"stageOne"];
[self presentViewController:viewController animated:YES completion:nil];
现在,尽管在控制第二个视图控制器的类中,我有一个属性设置,我正在尝试将数据发送到这,但它的工作效果很好。 我正在尝试以下操作:
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController * viewController = [storyBoard instantiateViewControllerWithIdentifier:@"stageOne"];
viewController.forename = @"Hello World";
[self presentViewController:viewController animated:YES completion:nil];
虽然这不起作用,但我得到的只是一个错误“在'UIViewController'类型的对象上找不到属性'forename'”。
感谢您的帮助,如果您能够给我一些示例代码,那将是非常棒的。
代码的问题是您访问了尚未在内存中创建的uicontrols。 您必须像这样更改语句的执行顺序...
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
holidayQuestion * viewController = [storyBoard instantiateViewControllerWithIdentifier:@"stageOne"];
[self presentViewController:viewController animated:YES completion:nil];
viewController.forename = @"Hello World";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.