Presentation is loading. Please wait.

Presentation is loading. Please wait.

Storyboard.

Similar presentations


Presentation on theme: "Storyboard."— Presentation transcript:

1 Storyboard

2 StoryBoard 介紹

3 StoryBoard IOS5 提供整合的介面 包含以下Controller: Table View Controller
Collection View Controller Navigation Controller Tab Bar Controller Page View Controller GLKit View Controller Or build your own 接下來要介紹interface builder,在創建專案的時候已經內建在裡面,用來設計手機的UI

4

5 UI Label Text Field Button Editable cancel Text View
在你專案中,一開始的Main.storyboad可以拖拉各種UI元件,直接視覺化的進行修改操作,可以在右下角選取Label標籤、Text Field文字區塊、Button按鈕、TextView文字欄等等UI元件,也可以點選元件後直接在右邊對元件的屬性像是顏色等等做修改。 Text Field Button Editable cancel Text View

6 頁面切換 開始的View Controller segue scene
每個App都會有一個起始頁面,也就是剛開始執行時,會出現的畫面,會有一個箭頭指向此頁面來代表初始頁面,且IOS的每個頁面可以藉由Main. Storyboard彼此直接連接做切換,只要按住滑鼠右鍵或是Ctrl鍵並拖拉到另一個要連接的頁面,就會讓此兩個頁面彼此連通,例如我將一個按鈕連到另一個頁面,則每當我點擊此按鈕時,就會切換到那個我所相連的頁面,被相連的頁面我們稱為Scene,相連的這條線我們可以稱它為一個Segue。 segue scene

7 Segue 相連的Segue可以給定一個固定Identifier ID,使我們可以藉由此ID來辨別是何處的Segue。

8 Segue相關方法 UIViewController類別
(BOOL)shouldPerformSegueWithIdentifi er: (NSString *)identifier sender:(id)sender 決定此id的segue是否被驅動(切換到下一 頁),預設是會回傳true(切換到下一頁), 若要進行相關程式後再決定是否切換到下 一頁,可覆寫此方法 identifier: segue的id字串 sender: 觸發此切換動作的元件,如:按鈕 Segue也有相關的內建函式可以呼叫。像是shouldPerformSegueWithIdentifier就是決定此Segue是否要被驅動

9 Segue相關方法 UIViewController類別
(void)prepareForSegue:(UIStoryboardSegue *) segue sender:(id)sender 通知即將切換到下一頁,segue將被執行 segue:此物見包含切換頁面涉及的view controllers sender:觸發此切換動作的元件 -(void)prepareForSegue則是即將要換下一頁

10 UIStoryboardSegue 類別 @property(nonatomic, readonly) id destinationViewController @property(nonatomic, readonly) id sourceViewController @property (nonatomic, readonly) NSString * identifier 一個Segue有來源(source)及目的(destination)還有此Segue ID(identity)三種屬性。

11 Unwind Segue 返回上一頁,須在返回的ViewController中加入 返回後要執行的方法,方法需有一個 UIStoryboardSegue 參數 建立返回按鈕與Exit的連線 若是一個返回上一頁的Segue,稱此Segue為一個Unwind Segue,此Segue會傳入一個(UIStoryboardSegue *)segue 參數。 - (IBAction)methodName:(UIStoryboardSegue *)segue { }

12 A離開要到B前,A程式的 (void)prepareForSegue:(UIStoryboardSegue
A離開要到B前,A程式的 (void)prepareForSegue:(UIStoryboardSegue *) segue sender:(id)sender方法會被呼叫,其中參數segue 的destinationViewController屬性可取得B程式物件,就可以透過設定B的屬性值來達到資料傳遞 1 -(void)prepareForSegue:(UIStoryboardSegue *) segue sender:(id)sender{ ViewControllerB *dst= segue.destinationViewController; } 2 - (void)viewDidLoad{ [super viewDidLoad]; //更新相關畫面 } Segue->dst A程式 B程式 ViewControllerA --有屬性, 如:NSString data1; ViewControllerB --有屬性, 如:NSString data2; Segue的生命週期,由A程式連到B程式,首先離開A到B程式,呼叫prepareForSegue,接著到達B程式的ViewDidLoad初始狀態,接著B程式呼叫上一頁時,又呼叫到void)prepareForSegue,進到A程式的viewWillAppear函式中。,因此我們可藉由Segue來做兩程式相關的資料傳遞工作。 4 Unwind方法 -(IBAction)Submit:(UIStoryboardSegue *)segue{ //更新相關畫面 } 或是 -(void)viewWillAppear:(BOOL)animated{ dst<-Segue 3 離開要到A前,B程式的 (void)prepareForSegue:(UIStoryboardSegue *) segue sender:(id)sender方法會被呼叫,資料傳遞方式與A傳遞到B相同


Download ppt "Storyboard."

Similar presentations


Ads by Google