ios開發中UITabBarController與UINavigationController混合使用是很多app的基礎頁面結構,下面是簡單的的頁面初始化的方法,在AppDelegate.m的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
中加入如下代碼
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; //初始化tabbar並設置為根視圖 tabBarViewController = [[UITabBarController alloc]init]; [self.window setRootViewController:tabBarViewController]; //初始化視圖並注入tabbar作為子視圖 MainViewController* first = [[MainViewController alloc]init]; first.title = @"首頁"; first.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首頁" image:[UIImage imageNamed:@"singleicon.png"] selectedImage:[UIImage imageNamed:@"singleicon.png"] ]; //初始化navigation並把navigation加入到tabbar中 UINavigationController * navFirst = [[UINavigationController alloc]initWithRootViewController:first]; [tabBarViewController addChildViewController:navFirst]; BobMyInfoTableViewController* second = [[BobMyInfoTableViewController alloc]init]; second.title = @"我的信息"; second.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我" image:[UIImage imageNamed:@"doubleicon.png"] selectedImage:[UIImage imageNamed:@"doubleicon.png"]]; UINavigationController * navSec = [[UINavigationController alloc]initWithRootViewController:second]; [tabBarViewController addChildViewController:navSec];
有錯誤歡迎指正。Stay Hungry Stay Foolish