如何在iOS中的不同视图控制器之间传递变量

时间:2015-06-02 13:17:49

标签: ios objective-c

我尝试使用此代码,但它对我不起作用。 谢谢

-(void)passvar:(NSString *)user
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"signupvc"];

viewController.user = user;

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

}

1 个答案:

答案 0 :(得分:1)

void MyModernTab_SelectedSourceChanged(object sender, SourceEventArgs e) { if (e.Source.OriginalString.EndsWith("Foo.xaml")) { var url = "/Pages/Foo.xaml"; var bb = new BBCodeBlock(); bb.LinkNavigator.Navigate(new Uri(url, UriKind.Relative), this, NavigationHelper.FrameTop); } } 没有UIViewController属性。 您应该使用自定义子类而不是user

UIVIewController

请注意,在此代码中,您从故事板中实例化 new -(void)passvar:(NSString *)user { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; MyCustomViewController *viewController = (MyCustomViewController *)[storyboard instantiateViewControllerWithIdentifier:@"signupvc"]; viewController.user = user; [self presentViewController:viewController animated:YES completion:nil]; } 并将其呈现给用户。它与您在调用这些代码行之前打开的任何其他View Controller无关 如果您将此功能调用3次,则会打开3个不同的MyCustomViewController