蘋果官方是推薦我們將所有的UI都使用Storyboard去搭建,Storyboard也是一個(gè)很成熟的工具了。使用Storyboard去搭建所有界面,我們可以很迅捷地搭建出復(fù)雜的界面,也就是說能為我們節(jié)省大量的時(shí)間。我們還可以很直觀地看出各個(gè)界面之間的關(guān)系,修改起來也很方便。將來如果遇到需要作修改的地方,我們只需要找到相對應(yīng)的Storyboard就可以了,比起以前來說,快捷了不少。
接下來就來介紹一些如何使用StroryBoard頁面跳轉(zhuǎn)及傳值。下面是使用StroryBoard實(shí)現(xiàn)的純頁面跳轉(zhuǎn)的demo演示:

demo演示
StoryBoard頁面跳轉(zhuǎn)主要有三種方法:
1.通過使用StoryBoardID跳轉(zhuǎn)。
2.通過Segue跳轉(zhuǎn)。
3.頁面跳轉(zhuǎn)直接綁定到按鈕的點(diǎn)擊事件中,非常方便。
方法一:通過使用StoryBoardID跳轉(zhuǎn)
首先需要設(shè)置要跳轉(zhuǎn)到VC的StoryBoard ID,如圖:

設(shè)置VC的StoryBoardID
實(shí)現(xiàn)跳轉(zhuǎn)和傳值代碼:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
CADetailViewController *detail = [storyboard instantiateViewControllerWithIdentifier:@"CADetailViewController"];
//傳值方式跟我們代碼跳轉(zhuǎn)相同
detail.titleString = @"StoryBoardID跳轉(zhuǎn)";
[self.navigationController pushViewController:detail animated:YES];
方法二:通過Segue跳轉(zhuǎn)
同方法一差不多,需要配置Segue的identifier,如圖:

配置Segue的identifier
實(shí)現(xiàn)跳轉(zhuǎn)和傳值代碼:
[self performSegueWithIdentifier:@"DetailSegue" sender:nil];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"DetailSegue"]) {
//傳值形式
CADetailViewController *detail = segue.destinationViewController;
detail.titleString = @"Segue跳轉(zhuǎn)";
}
}
方法三:按住control鍵選中按鈕同時(shí)拖線到要跳轉(zhuǎn)到的視圖控制器內(nèi),選中跳轉(zhuǎn)方式即可。

方法三實(shí)際上也是通過 Segue跳轉(zhuǎn),會(huì)調(diào)用
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender方法。