ios頁面間跳轉方式總結


下面以OldViewController(oldC)的按鈕btn點擊後跳轉到NewViewController(newC)爲例說明:ios

1.Storyboard的segues方式小程序

 鼠標點擊按鈕btn而後按住control鍵拖拽到newC頁面,在彈出的segue頁面中選擇跳轉模式便可數組

優勢:操做方便,無代碼生成,在storyboard中展現邏輯清晰spa

缺點:頁面較多時不方便查看,團隊合做時可維護性差,多人合做時不建議使用這種方式orm

 

2.選項卡UITabBarController控制器開發

經過調用UITabBarController的addChildViewController方法添加子控制器it

實例代碼:io

UITabBarController *tabbarVC = [[UITabBarControllerallocinit]; 程序

    OldViewController *oldC = [[OldViewControllerinit];方法

    oldC.tabBarItem.title = @"控制器1";

    oldC.tabBarItem.image = [UIImageimageNamed:@"old.png"];

    NewViewController *newC = [[NewViewControllerinit];

    newC.tabBarItem.title = @"控制器2";

    newC.tabBarItem.image = [UIImageimageNamed:@"new.png"];

    // 添加子控制器(這些子控制器會自動添加到UITabBarController的viewControllers數組中)

    [tabbarVC addChildViewController:recent];

    [tabbarVC addChildViewController:friends];

優勢:代碼量較少

缺點:tabbar的ios原生樣式不太好看,(不經常使用,目前不建議使用),若是要使用,建議自定義tabbar

 

3.導航控制器UINavigationController

在oldC的btn的監聽方法中調用:

[self.navigationController pushViewController:newC animated:YES];  //跳轉到下一頁面

在newC的方法中調用:

[self.navigationController popViewControllerAnimated:YES];  //返回上一頁面

當有屢次跳轉發生並但願返回根控制器時,調用:

[self.navigationController popToRootViewControllerAnimated:YES];  //返回根控制器,即最開始的頁面

 

4.利用Modal形式展現控制器

在oldC中調用:

[self presentViewController:newC animated:YES completion:nil];

在newC中調用:

[self dismissViewControllerAnimated:YES completion:nil];

 

5.直接更改 UIWindowrootViewController

 

總結:

Storyboard方式適合我的開發小程序時使用,有團隊合做或者項目較大時不建議使用

UITabBarController由於目前系統的原生樣式不太美觀,不建議使用

推薦使用UINavigationController和Modal,無明顯缺點,並且目前大部分程序都使用這兩種方式,只是看是否須要導航控制器而肯定使用哪一種方案

相關文章
相關標籤/搜索