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. Java IO读写大文件的几种方式及测试

    读取文件大小:1.45G 第一种,OldIO: public static void oldIOReadFile() throws IOException{ BufferedReader br = n ...

  2. 《DevOps故障排除:Linux服务器运维最佳实践》读书笔记

    首先,这本书是Linux.CN赠送的,多谢啦~ http://linux.cn/thread-12733-1-1.html http://linux.cn/thread-12754-1-1.html ...

  3. 一致性Hash算法在Memcached中的应用

    前言 大家应该都知道Memcached要想实现分布式只能在客户端来完成,目前比较流行的是通过一致性hash算法来实现.常规的方法是将server的hash值与server的总台数进行求余,即hash% ...

  4. 10分钟搞定react-router

    1.路由的安装: $ npm install -S react-router 2.引入路由文件 import {Router, Route, browserHistory} from 'react-r ...

  5. Redis中的发布与订阅

    redis中实现发布与订阅相对于zookeeper非常简单.直接使用publish和subscribe就行. subscrible news; 订阅news这个channel publish news ...

  6. vim开发环境配置

    一.大饱眼福 看了效果图,肯定有人说, 这都有啥功能?就花哨? 告诉你,你说花哨就错了,开玩笑?我们程序猿可都是实打实的人,说谎都不会,咋会忽悠人呢. 下面我来告诉你,这都有些什么功能: 文件索引功能 ...

  7. (转载)OC学习篇之---代理模式

    在前一篇文章我们介绍了OC中的协议的概念,这篇文章我们就来介绍一下OC中的代理模式,关于代理模式,如果还有同学不太清楚的话,就自己去补充知识了,这里就不做介绍了,这里只介绍OC中是如何实现代理模式的. ...

  8. 数据结构 -- 图的最短路径 Java版

    作者版权所有,转载请注明出处,多谢.http://www.cnblogs.com/Henvealf/p/5574455.html 上一篇介绍了有关图的表示和遍历实现.数据结构 -- 简单图的实现与遍历 ...

  9. nodejs save遇到的一个坑

    混合类型因为没有特定约束,因此可以任意修改,一旦修改了原型,则必须 调用markModified() >>> person.anything = {x:[3,4,{y:'change ...

  10. 好用的shell命令行: fish的配置

    fish的可视化配置命令: $ fish_config 其配置文件夹为 ~/.config/fish. 1.要设置环境变量,在配置文件夹里新建 config.fish 文件,它会作为fish 启动时的 ...