你的位置:首页 > 软件开发 > 操作系统 > iOS Programming View Controllers 视图控制器

iOS Programming View Controllers 视图控制器

发布时间:2015-05-08 12:00:08
iOS Programming View Controllers  视图控制器 1.1 A view controller is an instance of a subclass of UIViewController.一个view control ...

iOS Programming View Controllers  视图控制器

iOS Programming View Controllers  视图控制器 

1.1 

A view controller is an instance of a subclass of UIViewController.

一个view controller 是一个UIViewController的子类。

A view controller manages a view hierarchy.

一个view controller 管理一个视图树。

It is responsible for creating view objects that make up the hierarchy, for handling events associated with the view objects in its hierarchy, and for adding its hierarchy to the window.

它负责创建view 对象,处理event,把视图树加到window上。

 

In this chapter, you will create an application named HypnoNerd. In HypnoNerd, the user will be able to switch between two view hierarchies – one for being hypnotized and the other for setting a reminder for hypnosis on a future date.

在本章中,你将创建两个视图,并能切换。

 

step1:Create a new iOS project (Command-Shift-N) from the Empty Application template. Name this project HypnoNerdiOS Programming View Controllers  视图控制器

创建一个新应用名字为HypnoNerd。

Step2

iOS Programming View Controllers  视图控制器

Step3: 创建UIViewController 的子类

iOS Programming View Controllers  视图控制器

Step4:Open BNRHypnosisViewController.h and change the superclass to UIViewController.

@interface BNRHypnosisViewController : UIViewController @end

打开BNRHypnosisViewController.h,将继承NSObject改成继承UIViewController 

 

1.2 The view of a view controller 

As a subclass of UIViewController, BNRHypnosisViewController inherits an important property: @property (nonatomic, strong) UIView *view;

作为UIViewController的子类,它继承了一个很重要的属性:UIView.

This property points to a UIView instance that is the root of the view controller's view hierarchy.

这个属性指定了一个UIView实例,而这个实例就是view controller

 iOS Programming View Controllers  视图控制器

A view controller's view is not created until it needs to appear on the screen. This optimization is called lazy loading, and it can often conserve memory and improve performance.

view controller 的view 总是到要显示到屏幕上时才创建。这样能解决内存和提升性能。

 

There are two ways that a view controller can create its view hierarchy:

有两种方式创建view controller 的view hierarchy.

 

(1)programmatically, by overriding the UIViewController method loadView.

编程  重写UIViewController 的loadView方法。

原标题:iOS Programming View Controllers 视图控制器

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。