Bre*_*son 3 xcode objective-c ios
抱歉,如果我的术语有点偏,对客观C来说是新的!我试图将值从一个UIViewController类传递给另一个.我正在使用故事板.我可以使用以下代码显示第二个ViewController:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
[self presentModalViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)
这很好.在我的第二个ViewController(FormView)头文件中,我设置了如下属性:
@interface FormController : UIViewController {
NSString *selectedBooking;
}
@property (nonatomic, retain) NSString *selectedBooking;
@end
Run Code Online (Sandbox Code Playgroud)
如何从第一个控制器"传递值"到第二个控制器?据我所知,我必须像这样设置属性:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
vc.selectedBooking = @"test";
[self presentModalViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)
这给了我错误:在'UIViewController'类型的对象上找不到属性'selectedBooking'.
设置属性的正确方法是什么?我还应该使用其他东西而不是instantiateViewControllerWithIdentifier吗?
谢谢
你需要施展它.
即
FormController *fc = (FormController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
fc.selectedBooking = @"test";
[self presentModalViewController:fc animated:YES];
Run Code Online (Sandbox Code Playgroud)
然后你的代码的其余部分将工作:D
| 归档时间: |
|
| 查看次数: |
4783 次 |
| 最近记录: |