用我自己的视图替换UIViewController根视图 [英] Replacing a UIViewController root view with my own view

查看:304
本文介绍了用我自己的视图替换UIViewController根视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将UIViewController根视图替换为子类化的UIView.

I'm trying to replace a UIViewController root view with a subclassed UIView.

在iPhone SDK的UIViewController类参考中的概述"部分中,说明如下:

In the iPhone SDK's UIViewController Class Reference, within it's Overview section, this is stated:

您使用UIViewController的每个实例来管理全屏视图.对于简单的视图控制器,这需要管理负责呈现您的应用程序内容的视图层次结构.典型的视图层次结构包括一个根视图(该类的view属性中提供对其的引用)以及一个或多个呈现实际内容的子视图.

You use each instance of UIViewController to manage a full-screen view. For a simple view controller, this entails managing the view hierarchy responsible for presenting your application content. A typical view hierarchy consists of a root view—a reference to which is available in the view property of this class—and one or more subviews presenting the actual content.

按照view属性上的链接,然后指出:

Following the link on the view property it then states:

如果视图控制器没有关联的视图控制器,则应重写loadView方法,并使用它创建根视图及其所有子视图.

If your view controller does not have an associated view controller, you should override the loadView method and use it to create the root view and all of its subviews.

如果将此代码放置在loadView中,则假定我正在使用自己的UIView子类MyView:

If this code was placed in loadView would it create the root view assuming I was using my own subclass of UIView called MyView:

self.view = [MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

谢谢//:)

推荐答案

您是正确的.当需要显示视图时,将调用loadView函数,而viewController的view属性是使用诸如presentModalViewController:animated:之类的函数时显示的视图.如果要从NIB加载视图而不是使用loadView,则只需在视图的属性选项卡中将视图的类更改为自定义子类即可.

You are correct. The loadView function is called when the view needs to be displayed, and the viewController's view property is the view that is displayed when using functions like presentModalViewController:animated:. If you are loading your view from a NIB instead of using loadView, then just change the class of the view to your custom subclass in the properties tab for that view.

这篇关于用我自己的视图替换UIViewController根视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆