如果我的术语稍微偏离一点,对目标C新增了道歉! 我想从一个UIViewController类传递一个值到另一个。我正在使用故事板。我能够使用下面的代码显示第二个ViewController:使用instantiateViewControllerWithIdentifier和故事板传递属性值
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
[self presentModalViewController:vc animated:YES];
这工作正常。在我的第二个视图控制器的(FormView控件)头文件我设置像这样的属性:
@interface FormController : UIViewController {
NSString *selectedBooking;
}
@property (nonatomic, retain) NSString *selectedBooking;
@end
如何从我的第一个控制器“值传递”到第二控制器?据我了解我必须设置该属性,象这样:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
vc.selectedBooking = @"test";
[self presentModalViewController:vc animated:YES];
这给我的错误:属性“selectedBooking”在类型的对象UIViewController中找不到。
什么是设置属性的正确方法?有什么我应该使用,而不是那个instantiateViewControllerWithIdentifier?
谢谢
谢谢,作品完美,赞赏 –
很高兴我能帮到你。 – Fogmeister