Skip to content

12 - iOS MVC

MVC

  • Program is divided into 3 logical units
    • Controller
    • Model
    • View

IOS

Communication

  • Communication management is the key

IOS

  • Controlles can communicate with their Model
  • Controlles can communicate with their Model and View
  • Model and View should never speak to each other!!!!

IOS

  • Can View communicate vith Controller?
    • Communication is blind and structured. Controller can specify a target on itself and hand out an action to the View.
      View sends the action when events happen in UI

All together

IOS

  • Sometimes View needs to synchronize with the Controller.
    • Will, should, did, …. (willScroll, shouldScroll, didScroll)
  • Controller sets itself as the View’s delegate.
    • Delegate is set via protocol.
  • Views do not own the data they display.
    • If needed, they have a protocol to acquire it.
    • Controllers are almost always that data source (not Model).
    • Controllers interpret/format Model information for View.
  • Can the Model talk directly to the Controller?
    • No, they are UI independent. But sometimes Model (network) needs to inform, that data has changed.
    • Broadcast (messaging) mechanism is used for this. Interested parties can subscribe to these messages (Controllers and Models).