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

    Presenting and Managing Views with UIViewController

    Problem
    You want to switch among different views in your application.


    Solution
    Use the UIViewController class.

    (

    Apple’s strategy for iOS development was to use the model-view-controller (MVC) division
    of labor.

    Views are what get displayed to users, while the model is the data that
    the app manages, or the engine of the app.

    The controller is the bridge between the model and the view.

    The controller, or in this case, the view controller, manages the relationship between the view and the model.

    )

    creating a view controller without a .xib file

    1. created an application using the Empty Application template in Xcode

    2. create a new view controller for your app

         a) In Xcode, select the File menu and then choose New → New File...

         b) In the New File dialog, make sure iOS is the selected category on the left and that
               Cocoa Touch is the chosen subcategory. Once you’ve done that, select the New
               Objective-C class

        c) On the next screen, make sure that the “Subclass of ” the text field says UIView
             Controller. Also make sure that neither the “Targeted for iPad” nor the “With XIB
             for user interface” checkboxes is selected

        d) Save your controller

       e) Now find the application:didFinishLaunchingWithOptions: method of the app
           delegate and instantiate the view controller and set it as the root view controller of
           your window

    - (BOOL) application:(UIApplication *)application
     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      self.viewController 
        = [[ViewController alloc] initWithNibName:nil bundle:nil];
    
      self.window 
        = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
      /* Make our view controller the root view controller */
      self.window.rootViewController = self.viewController;
    
      // set the view background
      self.window.backgroundColor = [UIColor whiteColor];
    
      [self.window makeKeyAndVisible];
    
      return YES;
    }

    Go ahead and run the app on the simulator. You will now see a plain white view on the
    screen. Congratulations! You just created a view controller, and now you have access to
    the view controller and its view object.

    if you had selected the “With XIB for user interface” checkbox, Xcode would have also generated a .xib file for you. In that
    case, you can load your view controller from that .xib file by passing the .xib file’s name(without the extension)

    self.viewController = [[ViewController alloc]
                                   initWithNibName:@"ViewController"
                                   bundle:nil];

  • 相关阅读:
    北京周末去哪儿 —— 玉渊潭
    Linux 添加中文字体库,解决Java 生成中文水印不显示问题
    海淀驾校拿本过程
    IOS 微信返回按钮事件控制弹层关闭还是返回上一页
    java 将mysql中Blob类型转为字符串或数字
    echarts 技巧自己的一些记录
    java发送post请求,使用multipart/form-data的方式传递参数,可实现服务器间文件上传功能(转)
    java 调用webservice接口wsdl,推荐使用wsdl2java,放弃wsimport
    北京周末去哪儿 —— 香山
    北京周末去哪儿 —— 百望山森林公园
  • 原文地址:https://www.cnblogs.com/davidgu/p/3543472.html
Copyright © 2011-2022 走看看