我是 obj-c/iOS 的新手,我在概念上至少无法理解 viewControllers。我已经阅读了很多 Apple Doc,我什至在 xCode 中在某种程度上使用了 viewController,但我仍然不太了解它们是什么,或者使用它们的最佳方法是什么。
多年来,我一直是一名 AS3 开发人员,所以我的思想在 MovieClips/Sprites 和显示列表的上下文中工作,以在屏幕上获取图形。
好吧,据我了解...
时尚,然后允许你和他们做点什么??最基本的意义是什么?
将显示对象添加到显示列表?
跟他们?
我正在使用有帮助的 Sparrow 框架,但我仍然希望能够了解 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.
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.
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.
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.
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.
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.
Yeah, its like a reference to the UIElement. You can then change whatever property of the UIImageView you want directly from the UIViewController
一些有用的链接:
关于ios - 无法理解 iOS 中的 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973466/