iOS開發中視圖 push/modal/popover/replace/custom 小結

來源:互聯網
上載者:User

在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不存在,那就去建立它吧。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.