storyboard 简介
中文名:故事版、串联图
storyboard 中间的一个屏幕称为一个 scene (场景),了;两个屏幕之间的转换称为 segue (过渡)。
新建一个storyboard
-
command+N 新建 storyboard ;
-
添加两个 View controller ;
-
使用 Button 连接连个场景 ;
-
设置哪一幕是入口点 ;
-
在 Info.plist 配置 Main storyboard file base name 就是刚刚常见的 storyboard 文件名 ;
-
创建 class 与每一个 View Controller 相关联 ;
7. 愉快的运行成功。。。
传递数据
- FirstViewController.m
#import "SecondViewController.h"
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
SecondViewController *second = segue.destinationViewController;
second.data = @"张飞来也。。。";
}
-
SecondViewController.h
@property(nonatomic,copy)NSString *data;
-
SecondViewController.m
NSLog(@"data=%@", self.data);
-
成功。。。
添加 Tab Bar Controller
-
选中要添加的 View Controller
-
成功
storyboard 和代码混合导航
#import "OneViewController.h"
#import "TwoViewController.h"
@interface OneViewController ()
@end
@implementation OneViewController
- (IBAction)go:(id)sender {
TwoViewController *t = [self.storyboard instantiateViewControllerWithIdentifier:@"second_id"];
[self presentViewController:t animated:YES completion:^{
}];
}