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. 带删除小图标的EditText

    import android.content.Context; import android.graphics.Rect; import android.graphics.drawable.Drawa ...

  2. Delphi中实现MDI子窗体(转)

        Delphi中实现MDI子窗体 用MDI实现浏览子窗口,具有窗口管理功能,同屏观看多个网页的内容  ① 多文档窗体(MDI) MDI窗体是一种具有主子结构的窗体体系,微软的Word便是其中的一 ...

  3. java线程实践记录

    框架构建过程中遇到需要用到线程的地方,虽然以前经常听到线程,也看过一些线程类的文章,但真正使用时还是遇到一些问题,此篇正式为了记录自己对线程实操的体会. 入口类代码: public class tes ...

  4. uoj #58. 【WC2013】糖果公园(树上莫队算法+修改操作)

    [题目链接] http://uoj.ac/problem/58 [题意] 有一棵树,结点有自己的颜色,若干询问:u,v路径上的获益,并提供修改颜色的操作. 其中获益定义为Vc*W1+Vc*W2+…+V ...

  5. STL源码分析读书笔记--第二章--空间配置器(allocator)

    声明:侯捷先生的STL源码剖析第二章个人感觉讲得蛮乱的,而且跟第三章有关,建议看完第三章再看第二章,网上有人上传了一篇读书笔记,觉得这个读书笔记的内容和编排还不错,我的这篇总结基本就延续了该读书笔记的 ...

  6. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  7. jszs 枚举算法

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

  8. cocos2dx android版本移植时的Error format not a string literal and no format arguments解决方案

    原文地址 : http://www.cnblogs.com/hhuang2012/p/3336911.html cocos2dx android版本移植时的Error format not a str ...

  9. gcc -D

    [gcc -D] -D name Predefine name as a macro, with definition 1. 通常debug和release版的区别就在于是否有DEBUG宏,DEBUG ...

  10. 串口 COM口 USB-TTL RS-232 RS-485 不同标准 区别 释疑

    http://blog.sina.com.cn/s/blog_6566538d0100r7p8.html Point (所有要点都在这,请仔细阅读): 1.串口.COM口是指的物理接口形式(硬件).而 ...