如何使用UIViewController将数据传递给ViewController

时间:2014-04-30 09:33:12

标签: ios

如何使用此代码将数据传递给ViewController?

UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

UIViewController *vc = [main instantiateViewControllerWithIdentifier:@"Catalog"];

[self presentViewController:vc animated:YES completion:nil];

我想将示例中的数据传递给 itemId ,如下所示:

ViewController *vc = [[ViewController alloc] initWithNibName:nil bundle:nil];

vc.itemId = 0;

[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:vc animated:YES completion:nil];

2 个答案:

答案 0 :(得分:2)

如果是UIViewController

,请输入ViewController
ViewController *vc = (ViewController*)[main instantiateViewControllerWithIdentifier:@"Catalog"];
vc.itemId = 0;
[self presentViewController:vc animated:YES completion:nil];

答案 1 :(得分:0)

这对你也有用。

ViewController *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"Catalog"];
vc.itemId =0;
[self presentViewController:vc animated:YES completion:Nil];