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

过程:

1.新建一个empty IOS项目。

2,新建三个UIviewController

分别为:FirstViewController,SecondViewController,ThirdViewController

1.在 Xcode 中,选择文件菜单,然后选择 New—New 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

IOS开发之路四(UITabBarController)的更多相关文章

  1. iOS开发RunLoop学习:四:RunLoop的应用和RunLoop的面试题

    一:RunLoop的应用 #import "ViewController.h" @interface ViewController () /** 注释 */ @property ( ...

  2. iOS 开发之路(使用WKWebView加载Html5) 四

    基于Swift 3 . Xcode 8 . iOS 10 下的WKWebView的使用. 首先是WKWebView的基本用法: var wk:WKWebView! var progBar:UIProg ...

  3. iOS 开发之路(WKWebView内嵌HTML5之图片上传) 五

    HTML5页面的图片上传功能在iOS端的实现. 首先,页面上用的是plupload组件,在wkwebview上存在两个坑需要修复才能正常使用. 问题:在webview上点击选择照片/相机拍摄,就会出现 ...

  4. iOS 开发之路(登陆页键盘遮挡输入框问题)一

    在学习开发登陆页的时候,遇到的问题分享如下: 首先是swift 3.0 中,NotificationCenter 设置 selector 如下: @IBOutlet weak var bottomCo ...

  5. ios开发runtime学习四:动态添加属性

    #import "ViewController.h" #import "Person.h" #import "NSObject+Property.h& ...

  6. iOS 开发之路(AES/DES加密实现) 三

    最近接触的这个项目由于以前服务器上用的是DES/CBC/PKCS5Padding加密方式,为了让在iOS上的加密结果与服务器端保持一致,我做了很多尝试,现在分享给大家.PS:现在不推荐用DES了,只是 ...

  7. IOS开发之路三(XML解析之KissXML的使用)

    最近再做一个项目需要用到xml的解析.今天查了一些资料自己做了一个小demo.纯OC没有界面.. 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用 ...

  8. ios开发之路十一(ARC forbids explicit message send of 'autorelease'错误)

    在ios中经常会遇到:ARC forbids explicit message send of 'autorelease' 或“ARC forbids explicit message send of ...

  9. IOS开发之路三(XML解析之GDataXML的使用)

    最近再做一个项目需要用到xml的解析.今天查了一些资料自己做了一个小demo.纯OC没有界面.. 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用 ...

随机推荐

  1. android 单独编译某个模块

    第一次下载好Android源代码工程后,我们通常是在Android源代码工程目录下执行make命令,经过漫长的等待之后,就可以得到Android系统镜像system.img了.以后如果我们修改了And ...

  2. Spring工厂方式创建Bean实例

    创建Bean实例的方式: 1) 通过构造器(有参或无参) 方式: <bean id="" class=""/> 2) 通过静态工厂方法 方式: &l ...

  3. php获取网站根目录

    php获取网站根目录方法一:<?phpdefine("WWWROOT",str_ireplace(str_replace("/","\\&quo ...

  4. javascript正则表达式简介

      javascript正则表达式 javascript正则表达式 regular expression是一个描述字符模式的对象: ECMAScript中的RegExp类表示正则表达式: String ...

  5. JS代码的简单重构与优化

    JS代码的简单重构与优化(适合新手) 原文  http://www.cnblogs.com/similar/p/5016424.html Demo . 1 //bad if (age > 20) ...

  6. Epic - Tic Tac Toe

    N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...

  7. 怎么去掉Xcode工程中的某种类型的警告

    XCode警告   问题描述  在我们的项目中,通常使用了大量的第三方代码,这些代码可能很复杂,我们不敢改动他们,可是作者已经停止更新了,当sdk升级或者是编译器升级后,这些遗留的代码可能会出现许许多 ...

  8. JavaWeb高性能开发(一)

    今日要闻: 淘宝删差评产业链 在你给出"差评""中评"后不久,有人会偷偷登录你的淘宝账户,把你之前给过的评价删除或改成"好评".而这种人就是 ...

  9. django 搭建自己的博客

    原文链接:http://www.errdev.com/post/4/ 每一个爱折腾的程序员都有自己的博客,好吧,虽然我不太喜欢写博客,但是这样骚包的想法却不断涌现.博客园虽好,可以没有完全的掌控感,搭 ...

  10. ubuntu 错误 & 解决

    1.ssh时出现“段错误(核心已转储)” 原因:说明与ssh有关的内核代码被修改过并且部分代码访问内存过界 解决:1.将内核代码被修改过的部分修改回来        2.sudo apt-get re ...