了解 uiview 和 uiviewcontroller

发布于 2024-12-22 15:41:45 字数 380 浏览 2 评论 0原文

请帮助我理解 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖 2024-12-29 15:41:45

据我了解 UIView 是 View 的视觉表示,控制器负责
这个观点对吗?

单个视图控制器通常负责整个视图层次结构。视图控制器管理相关内容的“全屏”或至少一个区域。

当我们使用 initwithnibname 创建 viewcontroller 实例时,我们以编程方式
将一些视图附加到某个控制器,换句话说,我们说他是控制器
负责绘制这个视图的是?

不——视图应该知道如何绘制自己。视图控制器可能会告诉视图要绘制什么,但视图需要知道如何将其渲染到当前图形上下文中。

如果我们不使用nib nae初始化它,它是否会自动找到nib?

可以。如果您为 nib 名称和包传递 nil,UIViewController 将尝试查找与视图控制器类的名称匹配的 nib。但是,如果您愿意,可以重写 -loadView 以编程方式创建您自己的视图。

但是presentModalViewController函数呢?他得到了viewcontroller参数
并显示视图,或者我不明白它的含义?

以模态方式呈现的视图控制器仍然对其视图层次结构负责。 -presentModalViewController: 真正处理视图控制器之间的关系——视图控制器的视图如何移动到屏幕上,以及完成后会发生什么。

并且也可以在没有 xib 文件的情况下创建视图,仅在
viewcontroller 并显示后?

是的,如果您愿意,您当然可以这样做。每个视图都有一个 -initWithFrame: 初始化程序,您可以使用它来初始化视图,尽管某些视图提供其他选项。例如,UIButton 有一个可用于创建按钮的 +buttonWithType: 方法。

as i understand UIView is a visual representation of View and controller is responsible for
this view right?

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.

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?

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.

if we do not init it with nib nae, does it find the nib automatically or not?

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.

but what about presentModalViewController function? he get the viewcontroller parameter
and display the view or i don't understand the meaning of it ?

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.

and also is it possible to make a view without xib file, only in
viewcontroller and after show it ?

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.

花辞树 2024-12-29 15:41:45

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文