2011-12-29 71 views

回答

3

創建要使用UIViewController S的NSArray。然後實例化一個UITabBarController並將viewControllers屬性設置爲此數組。然後將tabBarControllerview添加到窗口。所有這些都應該在AppDelegate.m文件中完成。例如:

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    UIViewController *vc1 = [[UIViewController alloc] init]; 
    UIViewController *vc2 = [[UIViewController alloc] init]; 
    CustomViewController *vc3 = [[CustomViewController alloc] init]; 

    NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil]; 
    [vc1 release]; [vc2 release]; [vc3 release]; 

    UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
    [tabBarController setViewControllers:viewControllers]; 

    [window addSubview:[tabBarController view]]; 
    [window makeKeyAndVisible]; 

    return YES; 
} 
相關問題