了解 uiview 和 uiviewcontroller
请帮助我理解 UiView 和 UIViewController 的概念,我知道它的工作原理类似于 mvc 模式,并且据我了解 UIView 是 View 的视觉表示,控制器负责该视图,对吧?当我们使用 initwithnibname 创建 viewcontroller 的实例时,我们以编程方式将一些视图附加到某个控制器,换句话说,我们说控制器负责绘制这个视图,是吗?
如果我们不使用nib nae初始化它,它是否会自动找到nib?
该附件也可以通过界面生成器实现,对吗?
但是presentModalViewController 函数呢?他获取 viewcontroller 参数并显示视图,还是我不明白它的含义?是否可以在没有 xib 文件的情况下创建视图,仅在视图控制器中并在显示之后进行?
pls help me to understand the conception of UiView and UIViewController, i know that it works like mvc pattern, and as i understand UIView is a visual representation of View and controller is responsible for this view right? and when we create an instance of viewcontroller with initwithnibname we programatically attach some view to some controller , in other words we say the controller that he is responsible for drawing this view yes?
if we do not init it with nib nae, does it find the nib automatically or not?
this attachment also possible through Interface builder , am i right?
but what about presentModalViewController function? he get the viewcontroller parameter and display the view or i don't understand the meaning of it ? and also is it possible to make a view without xib file, only in viewcontroller and after show it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单个视图控制器通常负责整个视图层次结构。视图控制器管理相关内容的“全屏”或至少一个区域。
不——视图应该知道如何绘制自己。视图控制器可能会告诉视图要绘制什么,但视图需要知道如何将其渲染到当前图形上下文中。
可以。如果您为 nib 名称和包传递 nil,UIViewController 将尝试查找与视图控制器类的名称匹配的 nib。但是,如果您愿意,可以重写
-loadView
以编程方式创建您自己的视图。以模态方式呈现的视图控制器仍然对其视图层次结构负责。
-presentModalViewController:
真正处理视图控制器之间的关系——视图控制器的视图如何移动到屏幕上,以及完成后会发生什么。是的,如果您愿意,您当然可以这样做。每个视图都有一个
-initWithFrame:
初始化程序,您可以使用它来初始化视图,尽管某些视图提供其他选项。例如,UIButton 有一个可用于创建按钮的+buttonWithType:
方法。A single view controller is generally responsible for an entire hierarchy of views. A view controller manages a "screenful," or at least an area, of related content.
No -- a view should know how to draw itself. A view controller might tell the view what to draw, but the view needs to know how to render that into the current graphics context.
It can. If you pass nil for the nib name and bundle, UIViewController will try to find a nib matching the name of the view controller's class. You can, however, override
-loadView
to create your own views programmatically if you prefer to do that.A view controller presented modally is still responsible for its view hierarchy.
-presentModalViewController:
really deals with the relationship between view controllers -- how the view controller's view is moved onto the screen, and what happens when it's done.Yes, you can certainly do that if you want to. Every view has an
-initWithFrame:
initializer that you can use to initialize a view, although some views provide other options. For example, UIButton has a+buttonWithType:
method that you can use to create a button.Apple 文档在这方面非常出色。首先阅读视图控制器编程指南。
您的视图不需要 nib/xib 文件。您可以通过编程方式创建它们。
The Apple documentation is excellent in this regard. Read the View Controller Programming Guide for a start.
You do not need a nib/xib file for your views. You can create them programatically.