需求描述:
故事板中,VIEW1与VIEW2有一条SEGUE连线。点击VIEW1中的按钮跳转至VIEW2,并且从VIEW1中传递值给VIEW2。
实现:
VIEW1.m
添加下面的事件方法,该方法在视图跳转时被触发。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"goView2"]) //"goView2"是SEGUE连线的标识
{
id theSegue = segue.destinationViewController;
[theSegue setValue:@"这里是要传递的值" forKey:@"strTtile"];
}
}
VIEW2.h
定义一个属性来接受SEGUE传递过来的值:
@property(nonatomic,weak)NSString *strTtile;
VIEW2.m
@synthesize strTtile;
......
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"接收到的值为: %@", strTtile);
}