Saturday, 15 June 2013

iOS -- When to create a child ViewController vs. a UIView Subclass? -


Maybe it's a silly question, but during iOS development, I've hit it several times.

Sometimes I will develop a visual component that I want to use on many screens, so I will decide the UIView subclass and I will make it something that I use in many places. I can do

Then, I'm starting to add functionality to it. Maybe it should answer NSNotification , or it should answer the touch of the user.

At a certain point, I am wondering if I actually add a UIViewController subclass, and add it to my UI as a child view controller.

Anyone have to draw the line between adding some behavior in UIView , and when a complete UIViewController ?

should use a controller at any time you need to control or control the data . The scenes are considered as stupid as possible, do not know what they are showing, but where you can easily reuse the sub-class and view controller. A good example is to say that you need to retrieve an app (or text) from a user through a popover controller and a model during your app. Create a general sub-class of UIViewController , which contains the textfield and a button. Then you can use this scene and it is you controller in any capacity. It was reused in popover, modal or elsewhere (and usually going back through the delegation). Since you are working with data, therefore you should not use the sole subclass of UIVUV.

From my experience, I use the sub code UIViewControllers more often then UIViews . It is difficult for me to understand whether you are talking about containers completely or reusing ideas in normal application workflow. Either way though this should be the same.

No comments:

Post a Comment