AppDelegate.h:
#import
@interface AppDelegate : UIResponder
{
UIWindow *window;
UITabBarController *tabBarController;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
AppDelegate.m:
#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "FifthViewController.h"
@implementation AppDelegate
@synthesize window;
@synthesize tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
tabBarController = [[UITabBarController alloc]init];
FirstViewController *firstViewController = [[FirstViewController alloc] initWithStyle:UITableViewStyleGrouped];
firstViewController.title = @"First";
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:firstViewController];
nav1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.title = @"Second";
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:secondViewController];
nav2.tabBarItem.title=@"Second";
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
thirdViewController.title = @"Third";
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
nav3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Third" image:[UIImage imageNamed:@"third"] tag:2];
FourthViewController *fourthViewController = [[FourthViewController alloc] init];
fourthViewController.title = @"Fourth";
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:fourthViewController];
nav4.tabBarItem.title=@"Fourth";
FifthViewController *fifthViewController = [[FifthViewController alloc] init];
fifthViewController.title = @"Fifth";
UINavigationController *nav5 = [[UINavigationController alloc] initWithRootViewController:fifthViewController];
nav5.tabBarItem.title=@"Fifth";
tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nav5, nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self.window addSubview:tabBarController.view];
return YES;
}
@end
0 意見:
張貼意見