蘋果ios介面間跳轉方法總結

來源:互聯網
上載者:User


下面以FirstViewController(FVC)的按鈕button點擊後跳轉到SecondViewController(SVC)為例說明:

方式一:Storyboard的segues方式

滑鼠點擊按鈕button然後按住control鍵拖拽到SVC頁面,在彈出的segue頁面中選擇跳轉模式即可

INVFNn

優點:操作方便,無代碼產生,在storyboard中展示邏輯清晰
缺點:頁面較多時不方便查看,團隊合作時可維護性差, 多人合作時不建議使用這種方式。

方式二:選項卡UITabBarController控制器

通過調用UITabBarController的addChildViewController方法添加子控制器,代碼執行個體如下:


UITabBarController *tabbarVC = [[ UITabBarController alloc ] init ];
FirstViewController *FVC = [[FirstViewController ] init ];
FVC.tabBarItem.title = @"控制器1" ;
FVC.tabBarItem.image = [ UIImage imageNamed : @"first.png" ];
SecondViewController *SVC = [[SecondViewController ] init ];
SVC.tabBarItem.title = @"控制器2" ;
SVC. tabBarItem.image = [UIImage imageNamed : @"new.png" ];
// 添加子控制器(這些子控制器會自動添加到UITabBarController的 viewControllers 數組中)
[tabbarVC addChildViewController :FVC];
[tabbarVC addChildViewController :SVC];

優點:代碼量較少

缺點:tabbar的ios原生樣式不太好看,(不常用,目前不建議使用),如果要使用,建議自訂tabbar

方式三:導航控制器UINavigationController

在FVC的button的監聽方法中調用:

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

在SVC的方法中調用:

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

當有多次跳轉寄生並希望返回根控制器時,調用:


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

方式四:利用 Modal 形式展示控制器

在FVC中調用:


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

在SVC中調用:

[ self dismissViewControllerAnimated: YES completion: nil ];

方式五:直接更改 UIWindow 的 rootViewController

總結:

Storyboard方式適合個人開發小程式時使用,有團隊合作或者項目較大時不建議使用
UITabBarController因為目前系統的原生樣式不太美觀,不建議使用
推薦使用UINavigationController和Modal,無明顯缺點,而且目前大部分程式都使用這兩種方式,只是看是否需要導航控制器而確定使用哪種方案

相關文章

聯繫我們

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