如何将一个视图上的值传递给storyboard中的另一个视图?

时间:2015-06-17 10:03:34

标签: objective-c xcode navigation storyboard

-(IBAction)btn:(id)sender {

    abcViewController *vc = [[abcViewController alloc]initWithNibName:@"abcViewController" bundle:nil];
    vc.str = @"hello";
    [self.navigationController pushViewController:vc animated:YES];
}

2 个答案:

答案 0 :(得分:0)

查看此代码

UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@" identifierName"];
vc.label = @" Text&#34 ;;
[self.navigationController pushViewController:vc animated:YES];

答案 1 :(得分:0)

假设您要使用storyboard将字符串值从一个视图发送到另一个视图。 在第一个视图中,控制器在.h文件中声明变量,如NSString str;在第二个视图中,控制器在.h中声明变量,如NSString newStr;。 然后在.m文件的第一个视图控制器中使用storyboard创建第二个视图对象 - SecondViewController * svc = [storyboard instantiateViewControllerWithIdentifier:@" SecondViewController"]; 并使用此对象将变量发送到第二个视图 -         svc.newStr = str;