IOS开发之路四(UITabBarController)
前两天看了看斯坦福大学的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)的更多相关文章
- iOS开发RunLoop学习:四:RunLoop的应用和RunLoop的面试题
一:RunLoop的应用 #import "ViewController.h" @interface ViewController () /** 注释 */ @property ( ...
- iOS 开发之路(使用WKWebView加载Html5) 四
基于Swift 3 . Xcode 8 . iOS 10 下的WKWebView的使用. 首先是WKWebView的基本用法: var wk:WKWebView! var progBar:UIProg ...
- iOS 开发之路(WKWebView内嵌HTML5之图片上传) 五
HTML5页面的图片上传功能在iOS端的实现. 首先,页面上用的是plupload组件,在wkwebview上存在两个坑需要修复才能正常使用. 问题:在webview上点击选择照片/相机拍摄,就会出现 ...
- iOS 开发之路(登陆页键盘遮挡输入框问题)一
在学习开发登陆页的时候,遇到的问题分享如下: 首先是swift 3.0 中,NotificationCenter 设置 selector 如下: @IBOutlet weak var bottomCo ...
- ios开发runtime学习四:动态添加属性
#import "ViewController.h" #import "Person.h" #import "NSObject+Property.h& ...
- iOS 开发之路(AES/DES加密实现) 三
最近接触的这个项目由于以前服务器上用的是DES/CBC/PKCS5Padding加密方式,为了让在iOS上的加密结果与服务器端保持一致,我做了很多尝试,现在分享给大家.PS:现在不推荐用DES了,只是 ...
- IOS开发之路三(XML解析之KissXML的使用)
最近再做一个项目需要用到xml的解析.今天查了一些资料自己做了一个小demo.纯OC没有界面.. 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用 ...
- ios开发之路十一(ARC forbids explicit message send of 'autorelease'错误)
在ios中经常会遇到:ARC forbids explicit message send of 'autorelease' 或“ARC forbids explicit message send of ...
- IOS开发之路三(XML解析之GDataXML的使用)
最近再做一个项目需要用到xml的解析.今天查了一些资料自己做了一个小demo.纯OC没有界面.. 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用 ...
随机推荐
- OpenGL ES之GLSurfaceView学习一:介绍
原文地址::http://120.132.134.205/cmdn/supesite/?uid-5358-action-viewspace-itemid-6527 GLSurfaceView是一个视图 ...
- n个数的最小公倍数
Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数,每个测 ...
- motan源码解读:注册中心zookeeper(1)
Apache ZooKeeper is an effort to develop and maintain an open-source server which enables highly rel ...
- To follow the path
look to the master, follow the master, walk with the master, see through the master, bec ...
- 配置spring管理的bean的作用域
.singleton 在每一个spring Ioc容器中一个bean定义只有一个对象实例.默认情况下会在容器启动时初始化bean,但我们可以指定bean节点的lazy-init = "tru ...
- effective c++:private继承
如果class间使用private继承关系,编译器就不会自动的将派生类转换为基类,而且private继承而来的成员都变为private属性. private继承意味着根据某物实现出,当我们想要避免重复 ...
- 使用ReflectionTestUtils解决依赖注入
概述 当使用junit来测试Spring的代码时,为了减少依赖,需要给对象的依赖,设置一个mock对象,但是由于Spring可以使用@Autoware类似的注解方式,对私有的成员进行赋值,此时无法 ...
- Spark RDD概念学习系列之RDD的缺点(二)
RDD的缺点? RDD是Spark最基本也是最根本的数据抽象,它具备像MapReduce等数据流模型的容错性,并且允许开发人员在大型集群上执行基于内存的计算. 为了有效地实现容错,(详细见ht ...
- static_cast, dynamic_cast, const_cast探讨
转自:http://www.cnblogs.com/chio/archive/2007/07/18/822389.html 首先回顾一下C++类型转换: C++类型转换分为:隐式类型转换和显式类型转换 ...
- Accessor Search Implementation Details
[Accessor Search Implementation Details] Key-value coding attempts to use accessor methods to get an ...