您的位置:首页 > 产品设计 > UI/UE

IOS Storyboard中使用Segue传值

2014-11-07 10:31 267 查看


IOS Storyboard中使用Segue传值


转载▼

需求描述:

故事板中,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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: