[iOS學習]iOS開發中視圖相關的小筆記:push、modal、popover、replace、custom

轉載自點擊打開鏈接


在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。

Push類型一般是需要頭一個界面是個Navigation Controller的。
是在navigation View Controller中下一級時使用的那種從右側劃入的方式

popover類型,就是採用浮動窗的形式把新頁面展示出來

replace類型就是替換

custom就是自定義跳轉方式啦。


視圖之間的數據傳遞
當你從當前場景中觸發一個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不存在,那就去創建它吧。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章