Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your current approach is correct.</p> <p>UIViews should do one and only one thing: paint a view when asked to.</p> <p>UIViewControllers are more complex. They are are responsible for setting up views with any data they need to do their job, compositing multiple views (or view controllers) together if needed, responding to events from view components or from the device in general, and communicating with the rest of the code/system.</p> <p>Because your code wants to show two different kinds of information, it fits the UIViewController much better than the plain UIView style. </p> <p>As you've pointed out, Apple themselves have many examples of UIView subclasses that have delegates and do complex things. However, if you're writing a new component and it is complex (as yours is), I seriously recommend going for the UIViewController approach. </p> <p><strong>A note on history:</strong> Apple used to be of the advice that UIViewControllers should only show/composit UIViews and not other UIViewControllers (even though, confusingly, they didn't always follow their own advice!). This would align with their making of some quite complex UIView subclasses. However, they changed this stance a while back, and added support to UIViewControllers for compositing other UIViewControllers' views inside them. <strong>If Apple's stance had always been as it is now, you might find that some of their UIView subclasses were implemented as UIViewControllers!</strong></p> <p>As an experiment, it would probably be quite educational to try and implement your component both ways. I predict that you'd find UIView approach more unwieldy, with you having manually re-plumb some of the 'wiring' that you'd get 'for free' with the UIViewController approach.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload