IOS开发(54)之Storyboard之传值
1 前言
上一次我们介绍了storyboard的简单创建方法,这次我们来介绍一下如何通过storyboard进行两个viewcontroller之间的传值。
2 代码实例
2.1 新建一个不带nib文件viewcontroller文件
2.2 将storyboard中的第二个视图控制器的类设置为新建的secondview
2 .3 为视图过度的segue标识设置一个名称
zyviewcontroller.m
[plain]
//通知视图控制器,继续将被执行。uistoryboardsegue:一个uistoryboardsegue对象负责执行过渡两视图控制器。
- (void) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{
//原视图控制器
nslog(@"source controller = %@", [segue sourceviewcontroller]);
//目标视图控制器
nslog(@"destination controller = %@", [segue destinationviewcontroller]);
//过渡标识
nslog(@"segue identifier = %@", [segue identifier]);
if ([[segue identifier] isequaltostring:@"simpleseguetosecondviewcontroller"]){
zysecondviewcontroller *viewcontroller = [segue destinationviewcontroller];
viewcontroller.str = @"sdfsdfdsfdsfs";
}
}
//通知视图控制器,继续将被执行。uistoryboardsegue:一个uistoryboardsegue对象负责执行过渡两视图控制器。
- (void) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{
//原视图控制器
nslog(@"source controller = %@", [segue sourceviewcontroller]);
//目标视图控制器
nslog(@"destination controller = %@", [segue destinationviewcontroller]);
//过渡标识
nslog(@"segue identifier = %@", [segue identifier]);
if ([[segue identifier] isequaltostring:@"simpleseguetosecondviewcontroller"]){
zysecondviewcontroller *viewcontroller = [segue destinationviewcontroller];
viewcontroller.str = @"sdfsdfdsfdsfs";
}
}
zysecondviewcontroller.h
[plain]
#import <uikit/uikit.h>
@interface zysecondviewcontroller : uiviewcontroller
@property(nonatomic,copy)nsstring *str;
@end
#import <uikit/uikit.h>
@interface zysecondviewcontroller : uiviewcontroller
@property(nonatomic,copy)nsstring *str;
@end
zysecondviewcontroller.m
[plain]
- (void)viewdidload
{
[super viewdidload];
// do any additional setup after loading the view.
//test
nslog(@"str=======>%@",str);
}
-(void)dealloc{
[str release];
[super dealloc];
}
上一篇: 一加7T系列曝光:骁龙855 Plus+5G 或9月底亮相
下一篇: js正则取值的结果数组调试方法