ios - 了解uiview和uiviewcontroller

标签 ios cocoa-touch model-view-controller uiview uiviewcontroller

请帮助我理解 UiView 和 UIViewController 的概念,我知道它像 mvc 模式一样工作,并且据我所知 UIView 是 View 的视觉表示, Controller 负责这个 View ,对吗?当我们创建一个带有 initwithnibname 的 viewcontroller 实例时,我们以编程方式将一些 View 附加到某个 Controller ,换句话说,我们说他负责绘制这个 View 的 Controller 是吗?

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

这个附件也可以通过 Interface builder 实现,对吗?

但是 presentModalViewController 函数呢?他得到 viewcontroller 参数并显示 View 还是我不明白它的含义?并且是否可以在没有 xib 文件的情况下制作 View ,仅在 viewcontroller 中并在显示它之后?

最佳答案

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



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

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?



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

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



它可以。如果您为 nib 名称和 bundle 传递 nil,UIViewController 将尝试查找与 View Controller 类的名称匹配的 nib。但是,您可以覆盖 -loadView如果您愿意,可以通过编程方式创建自己的 View 。

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



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

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



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

关于ios - 了解uiview和uiviewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8606792/

相关文章:

iphone - 基准 UIView drawRect : method

php - 通过引用传递相对于使用全局的优势?

php - 预期类型 'object' 。在 PHP MVC 项目中发现 'void' .intelephense(1006) 问题

Python、Django 1.7 : Redirect all URLs to a single controller

iphone - 检查NSDate是在本周还是下周

iphone - 无法将 sqlite 数据库从应用程序的主包复制到用户文档

ios - iPhone模拟器图形损坏

ios - 所有浏览器和平台中的 HTML5 和视频捕获可能性

ios - 如何创建具有最大宽度的多行 UILabel?

iOS Document Reviewer 类似图像浏览器