Samsung SmartTV SDK Download and Installation
How to Create an Outlet for the Map Controller in Your iOS App
How to Create an Xcode Project for an iPad App

Basics of the Model-View-Controller Pattern in iOS

Model-View-Controller (MVC) is the most important pattern within iOS. It is frequently used in applications, particularly web applications, to isolate objects allowing for effective component design.

The pattern isolates the domain logic and core objects of the application (aka the model) from the application’s user interface. In this way, these important components (that is, the model and the views) can be designed, implemented, and maintained separately. The controller is placed between the model and the user interface.

The pattern isolates the domain logic and core objects of the application (aka the model) from the application’s user interface. In this way, these important components (that is, the model and the views) can be designed, implemented, and maintained separately.

The controller is placed between the model and the user interface. It receives user actions (such as The user clicked here) and translates those commands into actions on the model and then takes the resulting model updates and notifies the user interface to update itself.

Within iOS, controllers are called view controllers.

The Tic-Tac-Toe model consists of the classes Game, Grid, and Symbol. These classes encapsulate the domain logic of the game.

The Game, Grid, and Symbol classes are implemented so that they're completely independent of the application's user interface. You could use these classes just as they are in a command-line–driven, console-app version of Tic-Tac-Toe. Note that the logic of a game session is currently embedded in the Game Session view controller. You could also abstract a class representing a game session and make it part of the model.

The two major views in Tic-Tac-Toe are represented by Scene 1 and Scene 2 in the Tic-Tac-Toe storyboard.

image0.jpg

Objects that represent these views are instances of UIView and are created behind the scenes (no pun intended) by the iOS runtime. The buttons, text fields, and Board class that represent the Tic-Tac-Toe grid are subordinate views within these main views.

Finally, note that the Game View class (named TTTGameView and implemented in the files TTTGameView.h and TTTGameView.m) is also a view. It encapsulates the user-interface elements in Scene 2 (the board and the two text fields that show the scores and the game status, respectively).

Corresponding to the two scenes are two view controllers in Tic-Tac-Toe: the Game Options view controller and the Game Session view controller.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Add and Set Up the EventPageController in the MainStoryboard in Your iOS App
How to Use the Library Pane for iOS App Development
How to Join the Apple Developer Program
How to Add a Toolbar to Your iOS App
Create a New Project for Developing a Samsung SmartTV Application
Advertisement

Inside Dummies.com