`
zl4393753
  • 浏览: 340352 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

UITabBarController 使用

 
阅读更多

NCAppDelegate.h
#import <UIKit/UIKit.h>

@interface NCAppDelegate : UIResponder <UIApplicationDelegate> {
    UIWindow *window;
	UITabBarController *tabBarController;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;

@end



NCAppDelegate.m
@synthesize window;
@synthesize tabBarController;

- (void)dealloc
{
    [window release];
    [tabBarController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    
    tabBarController = [[UITabBarController alloc] init];
    
    HomeViewController *vc1 = [[HomeViewController alloc] init];
    MetionsViewController *vc2 = [[MetionsViewController alloc] init];
    FavoritesViewController *vc3 = [[FavoritesViewController alloc] init];
    ProfileViewController *vc4 = [[ProfileViewController alloc] init];
    
    NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2,vc3,vc4, nil];
    
    tabBarController.viewControllers = controllers;
    
    [window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
    return YES;
}


HomeViewController.m
@implementation HomeViewController

- (id)init {
    if (self = [super init]) {
        self.title = @"主页";
        UIImage* anImage = [UIImage imageNamed:@"home_default.png"];
        UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"主页" image:anImage tag:0];
        self.tabBarItem = theItem;
        [theItem release];
    }
    return self;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics