您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 使用技巧 >> iOS 7 技巧

Cocoa 程式設計中的分頁控制器與視圖類別

編輯:iOS 7 技巧

UITabBarController 常用於在底部提供多個功能入口,讓使用者能在不同視圖控制器之間切換,而不必像導覽控制器那樣以堆疊方式推入或彈出。

建立分頁列

通常可在應用程式代理的 applicationDidFinishLaunching 中建立 UITabBarController,建立多個子控制器後,放入陣列並指定給 viewControllers 屬性。

UITabBarController *tabBarController = [[UITabBarController alloc] init];
MyViewController *vc1 = [[MyViewController alloc] init];
MyOtherViewController *vc2 = [[MyOtherViewController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil];
[window addSubview:tabBarController.view];

自訂分頁項目

可在各視圖控制器的 init 方法中建立 UITabBarItem,設定標題、圖片與標記,再指定給 tabBarItem 屬性。

委派回呼

實作 tabBarController:didSelectViewController: 可偵測使用者切換到哪個分頁,也能更新提示數字或儲存目前分頁狀態。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved