需求描述:
故事板中,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);
}
本文介绍如何在iOS应用开发中实现从VIEW1到VIEW2的视图跳转,并通过SEGUE连线传递值。具体步骤包括在VIEW1中设置segue标识并传递字符串值,在VIEW2中接收并打印传递过来的值。
195

被折叠的 条评论
为什么被折叠?



