zoukankan      html  css  js  c++  java
  • IOS 7 Study

    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];
    }
  • 相关阅读:
    C++编程之约定俗成的习惯(1)
    “亚信科技杯”南邮第七届大学生程序设计竞赛之网络预赛 (K L题解) CSS出题
    “亚信科技杯”南邮第七届大学生程序设计竞赛之网络预赛 (K L题解) CSS出题
    “亚信科技杯”南邮第七届大学生程序设计竞赛之网络预赛 (K L题解) CSS出题
    “亚信科技杯”南邮第七届大学生程序设计竞赛之网络预赛 (K L题解) CSS出题
    万万没想到(2) 南邮NOJ2058
    万万没想到(2) 南邮NOJ2058
    万万没想到(2) 南邮NOJ2058
    万万没想到(2) 南邮NOJ2058
    万万没想到(1) 南邮NOJ
  • 原文地址:https://www.cnblogs.com/davidgu/p/3557126.html
Copyright © 2011-2022 走看看