要實現的佈局效果是每個TabBar對應的視圖是帶導航欄的TableView視圖.
層次結構是:在一個MainTabBarViewController上加載TabBarItem,而每個TabBarItem對應的視圖是NavigationController視圖,NavigationController指定的根視圖是TableViewController.
代碼如下:
- (void)enterMainView {
LBQNewNoteViewController *newNoteViewController = [[LBQNewNoteViewController alloc]initWithNibName:@"LBQNewNoteViewController" bundle:nil];
UITabBarItem *newNoteTabBarItem = [[UITabBarItem alloc]initWithTitle:@"新建筆記" image:[UIImage imageNamed:@"login.png"] tag:0];
UINavigationController *newNoteNavigation = [[UINavigationController alloc]initWithRootViewController:newNoteViewController];
newNoteViewController.tabBarItem = newNoteTabBarItem;
[newNoteTabBarItem release];
LBQCharacterTableViewController *characterTableView = [[LBQCharacterTableViewController alloc]initWithNibName:@"LBQCharacterTableViewController" bundle:nil];
UITabBarItem *characterTabBarItem = [[UITabBarItem alloc]initWithTitle:@" 文字筆記" image:[UIImage imageNamed:@"CharacterLetter.png"] tag:1];
//characterTableView.tabBarItem = characterTabBarItem;
UINavigationController *characterNavigation = [[UINavigationController alloc]initWithRootViewController:characterTableView];
characterNavigation.tabBarItem = characterTabBarItem;
[characterTabBarItem release];
LBQPhotoTableViewController *photoTableView = [[LBQPhotoTableViewController alloc]initWithNibName:@"LBQPhotoTableViewController" bundle:nil];
UITabBarItem *photoTabBarItem = [[UITabBarItem alloc]initWithTitle:@"相冊筆記" image:[UIImage imageNamed:@"Album.png"] tag:2];
//photoTableView.tabBarItem = photoTabBarItem;
UINavigationController *ablumNavigation = [[UINavigationController alloc]initWithRootViewController:photoTableView];
ablumNavigation.tabBarItem = photoTabBarItem;
[photoTabBarItem release];
LBQAllNoteTableViewController *allNoteTableViewController = [[LBQAllNoteTableViewController alloc]initWithNibName:@"LBQAllNoteTableViewController" bundle:nil];
UITabBarItem *allNoteTabBarItem = [[UITabBarItem alloc]initWithTitle:@"全部筆記" image:[UIImage imageNamed:@"login.png"] tag:3];
UINavigationController *allNoteNavigation = [[UINavigationController alloc]initWithRootViewController:allNoteTableViewController];
allNoteNavigation.tabBarItem = allNoteTabBarItem;
// allNoteTableViewController.tabBarItem = allNoteTabBarItem;
[allNoteTabBarItem release];
NSMutableArray *items = [[NSMutableArray alloc]init];
// [items addObject:newNoteViewController];
[items addObject:newNoteNavigation];
[items addObject:characterNavigation];
[items addObject:ablumNavigation];
[items addObject:allNoteNavigation];
LBQMainTabBarController *mainTabBarController = [[LBQMainTabBarController alloc]initWithNibName:@"LBQMainTabBarController" bundle:nil];
[mainTabBarController setViewControllers:items];
[self presentViewController:mainTabBarController animated:YES completion:nil];
}