What are controller classes? [duplicate]

2019-07-04 06:30发布

This question already has an answer here:

What are controller classes, like uiviewcontroller? What's the difference between uiviewcontroller and uiview? Thanks!

2条回答
Viruses.
2楼-- · 2019-07-04 06:55

A bit of history here. Apple/NeXT did not used to include any predefined controller classes until about 10.4 or 10.5. Prior, everyone wrote their own controller classes. Apple the started creating NSWindowController, NSViewController, etc. so that programmers did not have to reinvent the wheel.

In fact, you don't have to us Apple's controller classes at all and just write your own. It's actually a good learning experience.

查看更多
一夜七次
3楼-- · 2019-07-04 07:17

Cocoa works using the Model-Controller-View concept in Object-Oriented Programming

In this system the model consists of objects that store and work with any data being used by the application, the view consists of the classes that actually control the how the application is displayed.

The controllers are objects that act as a go-between. The view gains its data through methods provided by the controller, which deals with the model directly.

There is a good explanation of this concept here: Cocoa Application Tutorial: Essence of Cocoa

查看更多
登录 后发表回答