码迷,mamicode.com
首页 > 其他好文 > 详细

StoryBoard的使用注意事项

时间:2015-08-17 11:40:38      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

一.什么是StoryBoard

UIStoryBoard是你可以用来定义用户界面的一种新的方式,像xib。与xib不同的是它可以同时管理多个ViewController,而且可以在UIStoryBoard中配置ViewController 之间的跳转关系。UIStoryBoard将原有工程中的所有xib文件集成在一起,用拖拽的方式建立起两个viewController之间的跳转关系,使得整个程序的UI跳转逻辑清楚明了。使用UIStoryBoard后,界面相关的代码编写将更少。

 

二.如何使用StoryBoard

1.新建一个空的工程,注释掉didFinishLaunchingWithOptions中return YES之前所有代码;

2.New—>User Interface—>StoryBoard

3.指定APP加载的StoryBoard文件

技术分享

 

4.设置初始加载视图控制器

技术分享

 

三.视图控制器的使用

1.设置segue Identifiler

storyBoard选择viewController—>Push segue to XXX—> storyboard Segue Identifiler

2.通过已连线的segue进行场景切换

  - (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender 

 

四.UItableview的使用

在UIStoryBoard当中可以直接在UITableView上定制cell

1.设置代理

技术分享

 

2.设置复用ID

技术分享

 

3.使用复用

if (indexPath.row%2) 

{

        TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"One"];

        return cell;

    }

    else

    {

        TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Two"];

        return cell;

    }

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Three"];

    UserModel *model = [_dataArr objectAtIndex:indexPath.row];

    cell.nameLabel.text = model.name;

    cell.scoreLabel.text = model.score;

    return cell;

五.导航控制器的使用

1.将一个viewController转为navigationController

Editor —> Embed In —>Navigation Controller

 

2.取到storyBoard中没有连线的控制器

SmartSearchResultController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SmartSearchResult"];

 

六.自定义Segue

当进行场景切换的时候,Segue就会触发以下方法

- (void)perform

{

    UIViewController *ctl = self.sourceViewController;

    [ctl dismissViewControllerAnimated:YES completion:nil];

}

七.分栏控制器的使用

 

八.如何进行页面传值

1.正向传值

//跳转页面,会走这个方法

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

  if ([segue.identifier isEqualToString:@"123"])

    {

//获取目标控制器:下一个控制器

        BlackViewController *black = segue.destinationViewController;

        black.name = @"Lilei";

    }

    if ([segue.identifier isEqualToString:@"456"])

    {

        [segue.destinationViewController setValue:@"18" forKey:@"age"];

    }

}

 

//在目标控制器中,要有这个属性,才能传值

@interface BlackViewController : UIViewController

@property (nonatomic,copy)NSString  *name;

 

2.反向传值

在上一级视图控制器当中实现一个方法,要满足以下格式

-(IBAction)+任意方法名+(UIStoryboardSegue *)+任意变量名

示例:

-(IBAction)unwind:(UIStoryboardSegue *)segue

//源视图控制器

@property (nonatomic, readonly) id sourceViewController;

作用:返回上一个场景时候调用

注意:传统的block,协议代理,通知中心,单例传值依然奏效)

 

StoryBoard的使用注意事项

标签:

原文地址:http://www.cnblogs.com/xiexianchan1991/p/4736044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!