我有一個應用這些相同的要求。它有一個UITabBar,並且在不同的選項卡中,每個UITableViewController在頂部都有一個UINavigationController導航欄。
這裏是我的應用程序代理如何處理這樣的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Create the UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
//Create the view controllers for our tabs
UITableViewController *vc1 = [[UITableViewController alloc] init];
UITableViewController *vc2 = [[UITableViewController alloc] init];
UITableViewController *vc3 = [[UITableViewController alloc] init];
UITableViewController *vc4 = [[UITableViewController alloc] init];
UITableViewController *vc5 = [[UITableViewController alloc] init];
//Create the Navigation Controllers for these views
UINavigationController *nc1 = [[[UINavigationController alloc]
initWithRootViewController:vc1] autorelease];
UINavigationController *nc2 = [[[UINavigationController alloc]
initWithRootViewController:vc2] autorelease];
UINavigationController *nc3 = [[[UINavigationController alloc]
initWithRootViewController:vc3] autorelease];
UINavigationController *nc4 = [[[UINavigationController alloc]
initWithRootViewController:vc4] autorelease];
UINavigationController *nc5 = [[[UINavigationController alloc]
initWithRootViewController:vc5] autorelease];
//Make an array containing the view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nc4, nc5, nil];
//The NSArray has retained these controllers, we can now release them.
[vc1 release];
[vc2 release];
[vc3 release];
[vc4 release];
[vc5 release];
[nc1 release];
[nc2 release];
[nc3 release];
[nc4 release];
[nc5 release];
//Assign the view controllers to the tab bar.
[tabBarController setViewControllers:viewControllers];
//Set tabBarController as rootViewController of window
[self.window setRootViewController:tabBarController];
//The window retains tabBarController, we can release our reference
[tabBarController release];
[self.window makeKeyAndVisible];
return YES;
}
享受!
「思考的正確方向」是Interface Builder :) – jtbandes
EricS,從以下示例開始:http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html# // apple_ref/DOC/UID/DTS40008913-簡介-DontLinkElementID_2 – magma