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. HTTP协议的状态码

    对于Web编程人员来说,熟悉了解HTTP协议的状态码是很有必要的,很多时侯可能根据HTTP协议的状态码很快就能定位到错误信息!今天整理了一下所有HTTP状态码. HTTP状态码(HTTP Status ...

  2. 状态管理cookie 案例

    1状态管理:服务器为了追踪同一个客户端发出的请求,将多次交互看成一个整体看待 2:cookie的生存时间,默认情况下,cookie保存在浏览器内存中,只要不关闭浏览器,cookie就一直存在 如果希望 ...

  3. redhat Enterprise Linux Server release 7.2(Maipo) 安装redis-stat

    项目需要在rh7.2安装redis-stat,各种编译不过.通过一步步跟踪编译错误日志发现时缺少各种开发库. 需要安装的库列表如下: zlib-devel openssl-devel readline ...

  4. 基于vagrant工具在win7下免密登录linux

    一.SSH加密方式 SSH采用的是"非对称密钥系统",即耳熟能详的公钥私钥加密系统,其安全验证又分为两种级别. 1. 基于口令的安全验证 这种方式使用用户名密码进行联机登录,一般情 ...

  5. HUE 安装

    1.从github网下载hue-master.zip (源代码包) 地址:https://github.com/cloudera/hue#development-prerequisites 2.安装依 ...

  6. 使用RSA非对称密钥算法实现硬件设备授权

    一.硬件设备授权 即用户在硬件设备输入一个序列号(或一个包含授权信息的文件),然后硬件设备便可正常使用.    二.授权方案 构思授权方案时,参考了下面网址的思路: http://bbs.csdn.n ...

  7. 本地虚拟机挂载windows共享目录搭建开发环境

    关闭防火墙(本地环境 直接关掉即可)service iptables stop检查是否安装了需要的samba软件包rpm –q samba如果没安装yum install samba system-c ...

  8. Azure Cloud中的Log4Net设置

    这里的Cloud包含Worker Role和Web Role,Role是运行在云主机中的,这里的主机和VM有所不同,Windows Azure Role Architecture.我们并没有和本地服务 ...

  9. HDU5874:Friends and Enemies

    题目链接: Friends and Enemies 分析: 是一道想法题,我们假设x个人互相敌对,然后有y个人与这x个人都是朋友,而这y个人互相敌对. 则有 x+y=m x*y<=n 举个例子: ...

  10. html5 canvas防微博旋转

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...