2

Let's say I am designing an iPad app that presents user a screen. The screen contains several "controls" that for the sake of this example can be simple labels with +/- signs that increment/decrement integer value presented by the label, making sure that the value doesnt exceed max number defined for each control (numerical up/down control, but could be anything that has some simple logic). As integers are manipulated some read only values are calculated (labels). Moreover each "control" should respond to a tap gesture (and for example increase value by 10) The question i want to ask is - how should I design such a screen in terms of MVC used in cocoa touch? Given that the view controller that manages the screen is called MainController:

  • Should numeric up/down controls be separate views containing all the logic (somehow violates MVC pattern) that are added to MainController.view?
  • Should numeric up/down controls be separate viewControllers (with a view attached to them of course) containing all the logic (more reasonable approach in terms of MVC - am I correct?)
  • Are touches/gestures processed on viewcontroller or view level?
adrin
  • 3,738
  • 8
  • 40
  • 60
  • If you found my answer helpful and matching your question, please mark it as a solving answer to raise your accept-rate (currently you got only 41%) – Till Jan 14 '11 at 15:35

1 Answers1

0
  • Up/Down controls should be filled with function through the screen's View-Controller (MainController)
  • There is no need for extra View-Controllers on that control-level -- in fact, Apple suggests that for such commom situations only one View-Controller exists (MainController)
  • Touches/Guestures are processed on View-Controller level (MainController)
Till
  • 27,559
  • 13
  • 88
  • 122
  • thanks for your answer! So does it mean that if I want to have like 5 up/down controls I need to add 10 buttons and 10 outlets and 10 IBActions to viewcontroller?Thats seems as an anti pattern but maybe I am overlooking something :) Or maybe should I extract up/down controls to a view? (If yes can i design the view itself in Iterface Builder) – adrin Sep 21 '10 at 10:39
  • If you want to easily read & manipulate the control's values, then you will make an outlet for that control. So, yeah, 10 outlets seems reasonable and should make your code readable. You can have all the controls share the same action. The control will be passed into the action (sender), but then you may have code to determine which control was hit so you can adjust the associated related fields. (If "homeLoanCtrl" changes, modify homeLoanTxt field...) So, perhaps different uiactions isn't so bad. – Dave Oct 06 '10 at 17:53
  • Very similar discussion: http://stackoverflow.com/questions/1264296/iphone-subview-design-uiview-vs-uiviewcontroller – Dave Oct 06 '10 at 18:04