如何使用此代码将数据传递给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];
答案 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];