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的更多相关文章

  1. Implementing Navigation with UINavigationController

    Implementing Navigation with UINavigationController Problem You would like to allow your users to mo ...

  2. 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 ...

  3. 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 ...

  4. iOS第八课——Navigation Controller和Tab bar Controller

    今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...

  5. IOS开发-UI学习-UINavigationController(导航控制器)的使用

    UINavigationController是IOS 中常用的功能,基本用法如下: 1.在AppDelegate.m中添加如下代码: #import "AppDelegate.h" ...

  6. IOS开发之控件篇UINavigationController第一章 - 介绍

    UINavigationController是一个比较常见的控件,它连接个视图,例如一个视图走到另外一个视图,之间的联系都可以用这个NavigationController的方法 一般都会由两个部分组 ...

  7. IOS - Create Push Segue Animation Without UINavigationController

    APPLE提供了三种storyboard segue的方式:push,modal,custom . push segue是系统预定义的跳转方式, 为了使其能正常工作,我们还必须加载UINavigati ...

  8. IOS 7 Study - UIViewController

    Presenting and Managing Views with UIViewController ProblemYou want to switch among different views ...

  9. ios中模态弹窗用法及UINavigationController基本用法

    - (void)viewDidLoad { [super viewDidLoad]; //点击按钮跳转 loginViewController *vc=[[loginViewController al ...

随机推荐

  1. android edittext不弹出软键盘

    方法一: 在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden 例如:< ...

  2. Php 笔记4-----php 细节知识

    从 php5开始  php.ini  register_globals参数为OFF  ,禁止全局变量. 以前的情况下,  全局变量是默认为On的 , 所以,浏览器的表单中控件,会自动根据name在服务 ...

  3. cdh5.4、cm5.4 安装详细步骤

    安装准备: 1.centos6.5 64位 虚拟机,内存分配4G.硬盘位20G 2.cm5.4 cdh5.4 包 安装步骤 一.centos安装完后,进行系统配置 1.关闭防火墙 service ip ...

  4. Web Farm和Web Garden的区别

    在这篇博文中,我将确切剖析Web Farm和Web Garden的区别和原理,以及使用它们的利弊.进一步地,我将介绍如何在各个版本的IIS中创建Web Garden. 英文原文 | Abhijit J ...

  5. 30个有关Python的小技巧

    从我开始学习python的时候,我就开始自己总结一个python小技巧的集合.后来当我什么时候在Stack Overflow或者在某个开源软件里看到一段很酷代码的时候,我就很惊讶:原来还能这么做!,当 ...

  6. 使用Java进行MD5加密

    使用Java自带的MessageDigest类可以轻松实现MD5加密,只不过加密后得到的是byte数组,我们需要将其转换为16进制的字符. 代码如下: package com.stepsoft.tes ...

  7. PostgreSQL的 fdw 跨库使用

    create extension postgres_fdw; ',dbname 'postgres'); create user mapping for android_market server s ...

  8. linux常用的一些命令(不断增加中)

    linux 下重启 apache: httpd -k restart 下面这些大多命令都可以在<鸟哥私房菜>的服务器中的“常用网络指令”和基础中的“程序与资源管理”中找到ps -aux 这 ...

  9. For Microsoft Azure Network VNET to VNET Connection

    将一个 Azure 虚拟网络 (VNet) 连接到另一个 Azure 虚拟网络非常类似于将虚拟网络连接到本地站点位置.这两种连接类型都使用虚拟网络网关通过 IPsec/IKE 提供安全隧道.连接的 V ...

  10. LCA of a Binary Tree

    236. Lowest Common Ancestor of a Binary Tree /** * 基础版 * 给定p,q都是在树中 * 有两种情况: * 1. p和q分布在LCA的两侧 * 2. ...