ios技术科技时代iOS

【Storyboard】Storyboard介绍及使用

2015-03-06  本文已影响6342人  刘大帅

参考文章

Storyboards Tutorial in iOS 7: Part 1

Storyboards Tutorial in iOS 7: Part 2


背景知识

Storyboard 在iOS5时引入,它能节约你创建UI的时间,先看一张storyboard的图: table view cell

默认是prototype cell.

有没有想过把prototype cell 用在不同的table view 中?我这样想过,了解了一下,发现目前storyboard还不支持,如果想曲线救国,实现起来挺复杂的,参见Reusable UITableView's prototype cell

8.Static Cell
如果用static cell,我们就不用为tableview创建data source,因为它就是个静态的cell,不需重用,所以,你可以把该cell上的UI控件拖拽到对应的controller(Prototype cell是不行的),如图:

static cellstatic cell 拖拽static cell上的控件到对应的controller拖拽static cell上的控件到对应的controller
9.添加bar button item 到导航栏
拖拽一个bar button item 到拥有导航栏的控制器上,而不是那个虚拟的navigation controller.

10.segue

我们在前面说过container view controller 有一种relationship segue,它表示一个container view controller上所拥有的view controller,另外,就是用于view controller之间过渡的segue,它可以由button,cell,gesture等等来触发。

它的优势在于,节省很多代码量,很直观,你不用再写什么方法,或者像xib那样连接诸如IBAcation之类的东西。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"AddPlayer"]) {
 
        UINavigationController *navigationController = segue.destinationViewController;
        PlayerDetailsViewController *playerDetailsViewController = [navigationController viewControllers][0];
        playerDetailsViewController.delegate = self;
    }
}  

注意:记得给segue添加Identifier

上一篇下一篇

猜你喜欢

热点阅读