IPhone One controller, multiple types

I'm new to iPhone development and I'm wondering how to load multiple views from one controller.

I come from a C # background and am still trying to figure out how things work in the ObjC and iPhone worlds.

As a basic example of what I am trying to achieve, say I have a ClockController, a clock controller has basic methods for calculating time.

Now I want this controller to be able to display any number of views that support the basic ClockContollers interface.

Suppose I have one view that displays the clock as a digital output and another that makes it analog (a basic example I know of).

How can you achieve this?

Sorry if this is a very basic question, but I'm new to this.

Thank you in advance

+2


source to share


2 answers


Here's my understanding of how to apply MVC to your example: The
clock you draw on the screen are internal views, each supported by an instance of your clock controller controller. These controllers each interact with the clock model and update their views as needed. It is in this class that the property will be set that determines whether the clock is digital or analog.
It looks like your "ClockController" is really a data model / class. You can only have one instance of this model class, or one for each of your clock controllers (if they have different times).



+2


source


In my applications, I have many instances of a single view controller, which then uses different or multiple views to render the UI. You can view the view and all its children and add it to the view controller using addSubView and remove this view and all its subroutines using removeFromSuperview. This works well if the view only displays information and is subclassed to handle its differences from other views that the view controller needs to handle. In your case, the analog representation of the clock should be drawn in one direction, and the digital representation of the clock in the other. The controller just has to tell each view what time is and the view handles the translation into visual data.If your view accepts user input by dragging analog hands to set an alarm, then a subclass of the class should read that input and then translate to the alarm time and pass it back to the view controller. The controller does not need to know what type of clock the user is interacting with, but only sees the alarm time, which he needs to add in his turn.

However, when I have views that use very different user interfaces or for different purposes, I usually prefer to have one view controller for a set of views. Basically, I'm trying to use my views as a display, and my view manager as a manager for the data associated with that view (and any other views that might be supported by that same data).



For example, my game has one controller for playback, another for the high score table, and another one for settings.

+1


source







All Articles