swift - storyboard(故事版)的使用

來源:互聯網
上載者:User

標籤:tab   ble   ide   導航   cond   模式   iat   bundle   之間   

iOS開發中,蘋果公司提供了一種可視化的編程方式:即xib和storyboard,xib相對來說比較靈活,可以在純程式碼的項目中使用,

也可以和storyboard配合使用,用法都差不多,下面來總結一下故事版的使用方法:

1,初始

選中viewcontrolller,在屬性面板裡勾選Is Initial View Controller,即可設定為其實情境,前面會有灰色的小箭頭

2,將viewconroller的尺寸改成iPhone的大小

3,添加segue

使用segue的好處是,頁面的千幻不在需要建立任何代碼,按住ctrl鍵同事Tod‘s空間到目標情境,在彈出的操作功能表中選擇show

1)菜單中間4個是過去版本的使用方式,推薦最上面的4個新的方式:

Show:就是Push一個新的視圖

Show Detail:替換當前的視圖方式來展現新的視圖

Modally:強制回應視窗的方式

Popover:浮窗形式

2)如果兩個Controller之間建立包含關聯,例如從TableBarController到NavigationController,則操作功能表會有relationship的選項,選擇viewcontroller即可。

4,給segue添加關聯類別

在storyboard中添加一個segue時並不會同步添加對應的類,如果需要,得手動添加!

5,添加關聯代碼

主要有兩種關聯類別型,一種是outlet串連,就是在代碼裡面建立介面元素的成員變數引用,另一種是Action時間,把介面元素的相應時間方法添加到代碼裡來。

6,同一個storyboard裡多個View Controller的引用

如果要在代碼裡調用storyboard裡的View Controller,可以設定View Controller的identity。設定方法是,在stroyboard中選中View Controller,在右側的identity屬性面板裡設定StroyboardID。比如設定類Main.storyboard裡初始View Controller的identity為RootView,則通過以下方式引用:
var rootViewController = UIStoryboard(name: "Main", bundle: nil)            .instantiateViewControllerWithIdentifier("RootView") as UIViewController

對於初始Viewcontroller也可以不通過identity直接換區:

var rootViewController = UIStoryboard(name: "Main", bundle: nil)            .instantiateInitialViewController() as UIViewController

7,使用多個storyboard檔案

一個項目可以不止一個storyboard檔案,他們之間也可以互相調用,假如還添加一個XXX.storyboard,裡面的viewcontroller設定identity為secondView,則我們可以通過導航的方式來關聯兩個storyboard檔案。

在AppDelegate的Application入口裡把Main面板放入導航控制:

var rootViewController = UIStoryboard(name: "Main", bundle: nil)            .instantiateInitialViewController() as UIViewControllerself.window!.rootViewController = UINavigationController(rootViewController: rootViewController)

然後可以在RootView裡放入一個安潤,點擊事件裡導航到想要去的頁面:

var viewController = UIStoryboard(name: "Second", bundle: nil)            .instantiateViewControllerWithIdentifier("SecondView") as UIViewControllerself.navigationController?.pushViewController(viewController, animated: true)

 

 

 

swift - storyboard(故事版)的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.