IOS 7 Study - UIViewController

简介: Presenting and Managing Views with UIViewController ProblemYou want to switch among different views in your application.

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];

 

 

目录
相关文章
|
iOS开发
iOS - UIViewController生命周期(storyboard/Xib/纯代码)(下)
iOS - UIViewController生命周期(storyboard/Xib/纯代码)
|
iOS开发
iOS - UIViewController生命周期(storyboard/Xib/纯代码)(上)
iOS - UIViewController生命周期(storyboard/Xib/纯代码)
|
iOS开发
iOS对UIViewController生命周期和属性方法的解析(二)
iOS对UIViewController生命周期和属性方法的解析
223 0
iOS对UIViewController生命周期和属性方法的解析(二)
|
设计模式 前端开发 iOS开发
iOS对UIViewController生命周期和属性方法的解析(一)
iOS对UIViewController生命周期和属性方法的解析
249 0
iOS对UIViewController生命周期和属性方法的解析(一)
|
iOS开发
iOS开发之UIView与UIViewController的生命周期总结
iOS开发中,创建View常见的两种方式一个是纯代码,一个是借助于XIB;创建ViewController常见的也有两种方式一个是纯代码,一个是借助于StoryBoard。
1285 0
|
iOS开发
【iOS】UIViewController基类的实现
继承是面向对象编程语言的三大特性之一,写好基类会给App的开发带来极大的方便。在iOS开发中,一般一个页面就对应一个ViewController,ViewController在开发中用的也很多,写一个好的ViewController的基类,会让开发变得轻松很多。
1745 0
|
iOS开发 Swift 缓存
iOS - UIViewController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIViewController : UIResponder @available(iOS 2.0, *) public class UIViewController : UIResponder, NSCoding, UIAppearanceContainer, UITraitEnvironment, UIContentContainer, UIFocusEnvironment 视图控制器负责页面的创建、事件处理等。
1444 0
|
4天前
|
JavaScript 搜索推荐 Android开发
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
23 8
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
|
1月前
|
iOS开发 开发者
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
143 67
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
|
2月前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
90 11

热门文章

最新文章

  • 1
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
  • 2
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
  • 3
    Cellebrite UFED 4PC 7.71 (Windows) - Android 和 iOS 移动设备取证软件
  • 4
    【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
  • 5
    【01】噩梦终结flutter配安卓android鸿蒙harmonyOS 以及next调试环境配鸿蒙和ios真机调试环境-flutter项目安卓环境配置-gradle-agp-ndkVersion模拟器运行真机测试环境-本地环境搭建-如何快速搭建android本地运行环境-优雅草卓伊凡-很多人在这步就被难倒了
  • 6
    iOS8 中无需开源库的内置功能一览
  • 7
    iOS7应用开发7:自定义视图、手势操作
  • 8
    IOS小工具以及精彩的博客
  • 9
    Facebook SDK(iOS)初学讲解
  • 10
    iOS - Swift NSPoint 位置
  • 1
    【01】噩梦终结flutter配安卓android鸿蒙harmonyOS 以及next调试环境配鸿蒙和ios真机调试环境-flutter项目安卓环境配置-gradle-agp-ndkVersion模拟器运行真机测试环境-本地环境搭建-如何快速搭建android本地运行环境-优雅草卓伊凡-很多人在这步就被难倒了
    14
  • 2
    Cellebrite UFED 4PC 7.71 (Windows) - Android 和 iOS 移动设备取证软件
    28
  • 3
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    34
  • 4
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    29
  • 5
    【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
    23
  • 6
    uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
    143
  • 7
    【05】2025年1月首发完整版-篇幅较长-苹果app如何上架到app store完整流程·不借助第三方上架工具的情况下无需花钱但需仔细学习-优雅草央千澈详解关于APP签名以及分发-们最关心的一篇来了-IOS上架app
    235
  • 8
    app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
    90
  • 9
    深入探索iOS开发中的SwiftUI框架
    145
  • 10
    ios样式开关按钮jQuery插件
    60