ios - 无法理解 iOS 中的 viewController

标签 ios uiviewcontroller sparrow-framework

我是 obj-c/iOS 的新手,我在概念上至少无法理解 viewControllers。我已经阅读了很多 Apple Doc,我什至在 xCode 中在某种程度上使用了 viewController,但我仍然不太了解它们是什么,或者使用它们的最佳方法是什么。

多年来,我一直是一名 AS3 开发人员,所以我的思想在 MovieClips/Sprites 和显示列表的上下文中工作,以在屏幕上获取图形。

好吧,据我了解...

  • viewController 是一种处理图形的类
    时尚,然后允许你和他们做点什么??最基本的意义是什么?
  • 您似乎将 viewControllers 添加到 Window 类中,我猜这有点像
    将显示对象添加到显示列表?
  • 从最基本的意义上说,viewController 为您做了什么?
  • 是否有某些事情你绝对不能用它们做或不应该做
    跟他们?
  • viewControllers 是否需要以某种方式连接到 iOS 框架的其余部分才能运行(除了添加到窗口中)。
  • 他们究竟如何使用数据? (我已经阅读了 MVC,我知道从概念上讲这是一个稍微不同的问题)据我所知,您不会将数据硬编码到 viewController 中,那么 viewController 如何访问任何静态数据?
  • 假设我只是想在屏幕上显示一个图像,那么 viewController 在这个过程中究竟会扮演什么角色?它只是处理该过程的一小部分,还是整个节目并处理所有事情?
  • 一个 viewController 可以处理多个图像吗?就像它的术语一样,是屏幕上所有图像的“ Controller ”,还是一次处理一个图像?
  • 什么是与它处理的图像的 viewControllers 连接?它包含对它们的引用?

  • 我正在使用有帮助的 Sparrow 框架,但我仍然希望能够了解 viewController 是什么,因此我知道如何正确使用它们。

    哈,我为以上内容道歉,我知道我一定看起来完全糊涂了 :) 感谢您的任何建议。

    最佳答案

    希望这可以帮助你:

  • viewController 是一种以某种方式处理图形然后允许您对它们做某事的类?

    It's the glue between a View (Xib File) and the Data (Could be CoreData or whatever you're using in the backend). All the UI Elements you are using in the View you normally define as properties in the controller to get access to them.

  • 最基本的意义是什么?
    您似乎将 viewControllers 添加到 Window 类,我猜这有点像将显示对象添加到显示列表?

    I don't really know AS3 so I cannot compare Display lists with ViewControllers. But basically ViewControllers are there to handle different types of transitions between the views and accessing (setting/reading) the data which is displayed in the view.

  • 从最基本的意义上说,viewController 为您做了什么?

    Like I've written above. Most basic sense they interpret what the user does on the view and depending on the action of the user changes the model.

  • 是否有某些事情你绝对不能用它们做或不应该用它们做?

    It is always hard to keep the border between model and controller. They are pretty close to each other. So what I normally try is to delocate all logic stuff (like calculations, database access and so on) this does more belong into the model part. But of couse you're using these external classes in the controller.

  • viewControllers 是否需要以某种方式连接到 iOS 框架的其余部分才能运行(除了添加到窗口中)。

    Well like you already have written the ViewController needs to be connected to a view. Otherwise it would not make much sense. There are different subtypes of UIViewController such as UINavigationController where you probably need to overwrite some other methods to provide the whole functionality wanted by these special subtypes.

  • 他们究竟如何使用数据? (我已经阅读了 MVC,我知道从概念上讲这是一个稍微不同的问题)据我所知,您不会将数据硬编码到 viewController 中,那么 viewController 如何访问任何静态数据?

    There could be different approaches to store the data. Simplest way would be to have the data directly stored in the UIViewController. This could be a custom class which is the container of the data. All changes are directly written into this class and displayed by the UIViewController. But in most of the cases it makes sense to use CoreData (Which is responsible for reading/writing the data into a sqlite database). You could look at CoreData as your model and the UIViewController gets the data from there and passes the data which the UIViewController has received from the View back to it.

  • 假设我只是想在屏幕上显示一个图像,那么 viewController 在这个过程中究竟会扮演什么角色?它只是处理该过程的一小部分,还是整个节目并处理所有事情?

    The UIViewController would store an internal Property (UIImageView *) which is in the Interface Builder connected with the UIImageView you have created in the Xib file. So over these property you can change through your Controller the image.

  • 一个 viewController 可以处理多个图像吗?就像它的术语一样,是屏幕上所有图像的“ Controller ”,还是一次处理一个图像?

    Yes, this isn't a big problem. You can have as many images you want. You just need to have the properties defined in the UIViewController and linked to the View.

  • 什么是与它处理的图像的 viewControllers 连接?它包含对它们的引用?

    Yeah, its like a reference to the UIElement. You can then change whatever property of the UIImageView you want directly from the UIViewController


  • 一些有用的链接:
  • Apple Official ViewController Guide
  • Apple Official ViewController Basics
  • You should have a look at Storyboards (U can use them since IOS 5.0)
  • 关于ios - 无法理解 iOS 中的 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973466/

    相关文章:

    ios - 在导航 Controller 之外制作 UIViewController

    javascript - 列表项背景颜色在 Ipad 上不会改变

    ios - 如何创建SnapChat TableView效果

    c# - 麻雀工具包

    ios - 无法使用 xcodebuild 归档应用程序

    ios - 如何获得 subview 在我的 UITableViewCell 中相对于整个窗口的位置?

    ios - 来自 Xib 文件错误的 Swift init ViewController

    ios - 如何访问 iOS 中动态传递给子 viewController 的参数?

    objective-c - "Cannot find interface declaration for NSObject"?