IOS开发之路四(UITabBarController)

前两天看了看斯坦福大学的iphone开发公开课,讲的倒是不错,可看的我云里雾里的,不怎么讲基础和原理,不太适合初学者。今天看了一上午ios5基础教程这本书感觉有点头绪了。。。。废话少说,讲一讲我上午做的一个UITabBarController的例子。效果图如下:





过程:

1.新建一个empty IOS项目。



2,新建三个UIviewController

分别为:FirstViewController,SecondViewController,ThirdViewController

1.Xcode 中,选择文件菜单,然后选择 NewNew File;

2.New File 对话框中,确保左侧的 iOS 类和子类中的 Cocoa Touch 已经选择。一旦完成以上操作,选择对话框右侧的 UIViewController 子类,并点击下一步,如图 2-25 所示:


2-25. 新视图控制器子类3.在下个页面,确认文档区域的子类显示 UIViewController,并确认没有选择 the

Targeted for iPad 的和 With IXB for User Interface 复选框,如图 2-26 所示。点击下一步。


iOS 5 Programming Cookbook www.devdiv.com 翻译整理


2-26. 一个无 xib 文件的客户视图控制器

4.在下页面(保存为),将你的视图控制器文件命名为 Root-ViewController 并点击保存

键,如图 2-27 所示。



2-27. 保存一个无 xib 文件的视图控制器 


3.程序代理里的代码:

#import <UIKit/UIKit.h>
@class FirstViewController;
@class SecondViewController;
@interface Presenting_Multiple_View_Controllers_with_UITabBarControllerAppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) FirstViewController *firstViewController;
@property (nonatomic, strong)
UINavigationController *firstNavigationController;
@property (nonatomic, strong) SecondViewController *secondViewController;
@property (nonatomic, strong)
UINavigationController *secondNavigationController;
@property (nonatomic, strong) UITabBarController *tabBarController;
@end
既然我们已经声明到位了,那就开始在程序代理的编译文件里编译标签栏控件吧,

代码如下。
@synthesize window = _window; @synthesize firstViewController; @synthesize firstNavigationController; @synthesize secondViewController; @synthesize secondNavigationController; @synthesize tabBarController;
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:
[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.firstViewController = [[FirstViewController alloc] initWithNibName:nil
bundle:NULL];
self.firstNavigationController =
[[UINavigationController alloc] initWithRootViewController:self.firstViewController]; self.secondViewController = [[SecondViewController alloc] initWithNibName:nil
bundle:NULL];
self.secondNavigationController =
[[UINavigationController alloc] initWithRootViewController:self.secondViewController]; NSArray *twoNavControllers = [[NSArray alloc] initWithObjects:
self.firstNavigationController, self.secondNavigationController, nil];
self.tabBarController = [[UITabBarController alloc] init]; [self.tabBarController setViewControllers:twoNavControllers]; [self.window addSubview:self.tabBarController.view];
return YES;
}

FirstViewController里的代码如下:(另外两个相同)

//  FirstViewController.m
//  TableBarViewController
//
//  Created by WildCat on 13-8-5.
//  Copyright (c) 2013年 wildcat. All rights reserved.
//

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"First";
        self.tabBarItem.image = [UIImage imageNamed:@"menu.png"];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor redColor]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值