你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> Storyboard裡面的幾種Segue區別及視圖的切換:push,modal,popover,replace和custom

Storyboard裡面的幾種Segue區別及視圖的切換:push,modal,popover,replace和custom

編輯:IOS開發綜合

一、視圖切換類型介紹
在storyboard中,segue有幾種不同的類型,在iphone和ipad的開發中,segue的類型是不同的。
在iphone中,segue有:push,modal,和custom三種不同的類型,這些類型的區別在與新頁面出現的方式。
而在ipad中,有push,modal,popover,replace和custom五種不同的類型。
modal 模態轉換
 
最常用的場景,新的場景完全蓋住了舊的那個。用戶無法再與上一個場景交互,除非他們先關閉這個場景。
是在viewController中的標准切換的方式,包括淡出什麼的,可以選切換動畫。
Modalview:就是會彈出一個view,你只能在該view上操作,而不能切換到其他view,除非你關閉了modalview.
Modal View對應的segue type就是modal segue。
*Modal:Transition to another scene for the purposes of completing a task.當user在彈出的modalview裡操作完後,就應該dismiss the modal view scene然後切換回the originalview.
push

Push類型一般是需要頭一個界面是個Navigation Controller的。
是在navigation View Controller中下一級時使用的那種從右側劃入的方式
*Push:Create a chain of scenes where the user can move forward or back.該segue type是和navigation viewcontrollers一起使用。
popover(iPad only)
 
popover 類型,就是采用浮動窗的形式把新頁面展示出來
*Popover(iPad only):Displays the scene in a pop-up “window” over top of the current view.
 
 
*Replace (iPad only):
 
替換當前scene,
Replace the current scene with another. This is used in some specialized iPad viewcontrollers (e.g. split-view controller).
custom

就是自定義跳轉方式啦。
*Custom:Used for programming a customtransition between scenes.
在Storyboard中使用自定義的segue類型
 

一 、簡述
Storyboard是你可以用來定義用戶界面的一種新的方式,像xib。
與xib不同的是它可以同時管理多個ViewController,而且可以在Storyboard中配置ViewController 之間的跳轉關系。
 
二、Storyboard使用
如果你是創建新項目,Xcode模版可以提供一個配置好的Storyboard供你使用。對於其它的應用,使用Storyboard的過程如下:
1、配置應用程序Info.plist文件
添加UIMainStoryboardFile ,值為storyboard的文件名。
刪除原來的NSMainNibFile
2、像以前創建xib文件一樣創建一個storyboard文件
3、配置 storyboard中的viewController
 
三、Storyboard的創建
            你可以用InterfaceBuilder 去為你的應用程序創建一個Stroyboard,一般來說一個應用使用一個 Storyboard就夠了,但是如果你想創建多個也是可以的,只要你願意。一個 Stroyboard應該至少含有一個ViewController。
            在iPhone中,對於每一個在Storyboard的ViewController都管理著一個scene,每個scene又管理著screen上的東東,但對於iPad來說,多個scene可以同時呈現在一個screen上。你可以從library中拖拽viewController到你的Storyboard上。
            當你想關聯兩個viewController時,你可以按著control鍵,用鼠標從一個ViewController中的button,table view cell…拖拽連接到另一個你想跳轉到的ViewController,這樣就創建了一個segue,不要忘記設置identifier哦。
          
四、 Scene之間的數據傳遞
            當你從當前 scene中觸發一個segue的時候,系統會自動調用prepareForSegue:sender:這個方法。如果你想從一個界面切換到裡另一個界面的時候傳遞數據,你應該override這個方法。
A---》B
想把數據  NSString A_data   從AController傳到BController,則在BController中 
@property 一個NSString data
然後在AController中添加方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"The segue id is %@", segue.identifier );
    UIViewController *destination = segue.destinationViewController;  
    if ([destination respondsToSelector:@selector(setData:)])
    {
        [destination setValue:@"這是要傳遞的數據" forKey:@"data"];
    }   
}
之後,Bcontroller中的data屬性,就接收到數據了。
 
五、ViewController之間的跳轉
            1、如果在 Storyboard中當前的 ViewController和要跳轉的ViewController之間的segue存在,則可以執行performSegueWithIdentifier:sender:這個方法實現跳轉。
            2、如果目標ViewController存在Storyboard中,但是沒有segue。你可以通過UIStoryboard的instantiateViewControllerWithIdentifier:這個方法獲取到它,然後再用你想要的方式實現跳轉,如:壓棧。
            3、如果目標ViewController不存在,那就去創建它吧。

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved