When do you need to use a view controller?

I'm immersed in the development of the iPhone, and one of the main concepts I'm trying to get is view controllers. If you look at the GLPaint example on the apple dev website, you will see a project that has ...

  • Application Delegate Class
  • Subclass uiwindow
  • And a subclass of uiview

And the uiview subclass implements all the main graphics and handles touch events. My questions...

  • Why is there no view controller implemented to handle this view logic?
  • Could you use the view controller to implement this logic, or should it be implemented in a uiview subclass?
  • And last, when should you use a view controller to implement a logical view code?

Thank you for your help!

+3
source share
3 answers

View knows how to interact with the user. He knows how to display some data, how to handle events and how to give feedback to the user.

The view controller knows that, but now how. He knows what data to display and what to do in response to user action.

UIButton knows how to display the title and image, and how to track a click, but not what the title should be or what to do after the click.

UITableView , , , , . , .

, . tableview , . .

Edit:

, , :

  • .
  • .
  • .
  • .

, UIViewController. , UIViewController , NSObject - . , UIViewController UIViewController. UIViewController, , , , , .

, , UINavigationController. UIViewControllers. , . , UIViewController.

+2

, ( ), , . 2 drawRect UIView, UIViewController.

UIViewController, .xib.

(, a NSTimer) viewWillAppear viewDidAppear viewWillDisapper viewDidAppear. /, .

+1

, . view, UIView , , . , , mustRotateToInterfaceOrientation: 5 UIViews, .

MVC (model-view-controller).

. - . . , . . . , . , .

, .

0

Source: https://habr.com/ru/post/1749843/


All Articles