IOS 7 Study - Implementing Navigation with UINavigationController
Problem
You would like to allow your users to move from one view controller to the other with
a smooth and built-in animation.
Solution
Use an instance of UINavigationController.
What it's like
If you’ve used an iPhone, iPod Touch, or iPad before, chances are that you have already
seen a navigation controller in action. For instance, if you go to the Settings app on your
phone and then press an option such as Wallpaper (see follow)

1. Add UINavigationController property in app delegate implementation
#import "AppDelegate.h"
#import "FirstViewController.h" @interface AppDelegate () @property (nonatomic, strong) UINavigationController *navigationController; @end @implementation AppDelegate ...
2. Initialize our navigation controller using its initWithRootViewController: method and pass our root view controller as its parameter.
Then we will set the navigation controller as the root view controller of our window.
- (BOOL) application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FirstViewController *viewController = [[FirstViewController alloc]
initWithNibName:nil
bundle:nil];
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
3. FirstViewController implementation
#import "FirstViewController.h"
#import "SecondViewController.h" @interface FirstViewController () @property (nonatomic, strong) UIButton *displaySecondViewController; @end @implementation FirstViewController - (void) performDisplaySecondViewController:(id)paramSender {
SecondViewController *secondController = [[SecondViewController alloc]
initWithNibName:nil
bundle:NULL]; [self.navigationController pushViewController:secondController animated:YES];
} - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"First Controller";
self.displaySecondViewController = [UIButton buttonWithType:UIButtonTypeSystem];
[self.displaySecondViewController
setTitle:@"Display Second View Controller"
forState:UIControlStateNormal];
[self.displaySecondViewController sizeToFit];
self.displaySecondViewController.center = self.view.center;
[self.displaySecondViewController
addTarget:self
action:@selector(performDisplaySecondViewController:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.displaySecondViewController];
} @end
4. create this second view controller, without a .xib file
#import "SecondViewController.h"
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Second Controller";
}
- (void) goBack {
[self.navigationController popViewControllerAnimated:YES];
}
- (void) viewDidAppear:(BOOL)paramAnimated {
[super viewDidAppear:paramAnimated];
[self performSelector:@selector(goBack)
withObject:nil
afterDelay:5.0f];
}
IOS 7 Study - Implementing Navigation with UINavigationController的更多相关文章
- Implementing Navigation with UINavigationController
Implementing Navigation with UINavigationController Problem You would like to allow your users to mo ...
- IOS 7 Study - Manipulating a Navigation Controller’s Array of View
ProblemYou would like to directly manipulate the array of view controllers associated with aspecific ...
- IOS 7 Study - Displaying an Image on a Navigation Bar
ProblemYou want to display an image instead of text as the title of the current view controlleron th ...
- iOS第八课——Navigation Controller和Tab bar Controller
今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...
- IOS开发-UI学习-UINavigationController(导航控制器)的使用
UINavigationController是IOS 中常用的功能,基本用法如下: 1.在AppDelegate.m中添加如下代码: #import "AppDelegate.h" ...
- IOS开发之控件篇UINavigationController第一章 - 介绍
UINavigationController是一个比较常见的控件,它连接个视图,例如一个视图走到另外一个视图,之间的联系都可以用这个NavigationController的方法 一般都会由两个部分组 ...
- IOS - Create Push Segue Animation Without UINavigationController
APPLE提供了三种storyboard segue的方式:push,modal,custom . push segue是系统预定义的跳转方式, 为了使其能正常工作,我们还必须加载UINavigati ...
- IOS 7 Study - UIViewController
Presenting and Managing Views with UIViewController ProblemYou want to switch among different views ...
- ios中模态弹窗用法及UINavigationController基本用法
- (void)viewDidLoad { [super viewDidLoad]; //点击按钮跳转 loginViewController *vc=[[loginViewController al ...
随机推荐
- Java并发编程-synchronized
多线程的同步机制对资源进行加锁,使得在同一个时间,只有一个线程可以进行操作,同步用以解决多个线程同时访问时可能出现的问题.同步机制可以使用synchronized关键字实现.synchronized关 ...
- CRF模型
CRF的全称是Conditional Random Fields,由CMU教授John Lafferty 提出,原文标题:Conditional R andom Fields: Probabilist ...
- Qt之操作数据库(SQLite)
SQLite 简介 SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需 ...
- vim7.4 安装 k-vim
注:在虚拟机 kali 1.9中安装完成之后,无法连接到网络(目前没找到有效的解决方法,不知道是不是通病,本人安装了两次,都一样),cpu占用率 70%+ ,建议安装之前,先建立快照,否则,后悔莫极 ...
- Python进程和线程
引入进程和线程的概念及区别 1.线程的基本概念 概念 线程是进程中执行运算的最小单位,是进程中的一个实体,是被系统独立调度和分派的基本单位,线程自己不拥有系统资源,只拥有一点在运行中必不可少的资源,但 ...
- asp web api 怎么使用put和delete。
Method Overriding RESTful services allow the clients to act on the resources through methods such as ...
- Python 代码性能优化技巧(转)
原文:Python 代码性能优化技巧 Python 代码优化常见技巧 代码优化能够让程序运行更快,它是在不改变程序运行结果的情况下使得程序的运行效率更高,根据 80/20 原则,实现程序的重构.优化. ...
- 由于SSH配置文件的不匹配,导致的Permission denied (publickey)及其解决方法。
读者如要转载,请标明出处和作者名,谢谢.地址01:http://space.itpub.net/25851087地址02:http://www.cnblogs.com/zjrodger/作者名:zjr ...
- 动软代码生成与 EntityFramework 实体生成模板
有用到EntityFrameWork的同学们,可以用用. 实体工程中添加EF6的dll 还有 ValidBox4Mvc.ValidRules.dll应用到项目中,此dll下载地址:http://www ...
- 三、 将DataTable 转换为List
1. 方法public static IList<T> ConvertTo<T>(DataTable table) { if (table == null) { return ...