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不存在,那就去創建它吧。
轉載于:https://www.cnblogs.com/Free-Thinker/p/5001931.html
總結
以上是生活随笔為你收集整理的iOS开发中视图相关的小笔记:push、modal、popover、replace、custom的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员有趣的面试智力题(转)
- 下一篇: linux下测试宽带速度