什么时候在iPhone上使用UIView与UIViewController? [英] When to use a UIView vs. a UIViewController on the iPhone?

查看:80
本文介绍了什么时候在iPhone上使用UIView与UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是想知道什么时候在iPhone上使用UIView和UIViewController。



我理解你不应该使用UIViewController,除非它是一个



例如,我想建立一个模态覆盖 - 一个屏幕将滑入当前屏幕的位置。如果这种模态覆盖是全屏的,应该是一个UIViewController?最后一次我建立这样的东西,我子类化了UIViewController,但现在我想知道是否正确。

解决方案

a href =https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/index.html =nofollow noreferrer> iOS控制器编程指南:



视图控制器最重要的角色是管理视图层次,每个视图控制器都有一个根视图,包含所有视图控制器的内容。



有两种类型的视图控制器:




  • 内容视图控制器管理应用程序内容的离散部分,是您创建的主要视图控制器类型。

  • 容器视图控制器从其他视图控制器(称为子视图控制器)收集信息,并以便于导航或以不同方式显示这些视图控制器的内容。



大多数应用程序是两种类型的视图控制器的混合。


I have always sort of wondered when to use a UIView vs. a UIViewController on the iPhone.

I understand that you shouldn't use a UIViewController unless it's a full-screen view, but what other guidelines are there?

For example, I want to build a modal overlay - a screen that will slide into place over the current screen. If this modal overlay is full-screen, should it be a UIViewController? The last time I built something like this, I subclassed UIViewController, but now I wonder if that was correct.

解决方案

From Apple's View Controller Programming Guide for iOS:

"The most important role of a view controller is to manage a hierarchy of views. Every view controller has a single root view that encloses all of the view controller’s content. To that root view, you add the views you need to display your content."

Also:

"There are two types of view controllers:

  • Content view controllers manage a discrete piece of your app’s content and are the main type of view controller that you create.
  • Container view controllers collect information from other view controllers (known as child view controllers) and present it in a way that facilitates navigation or presents the content of those view controllers differently.

Most apps are a mixture of both types of view controllers."

这篇关于什么时候在iPhone上使用UIView与UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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