Question on Theory (Silver Challenge)


#1

Hi all,

I’m a UI developer but I’m new to iOS. I think some of my existing experience and practices are getting in the way of my learning.

I’m on chapter 7 and was stuck on the Silver Challenge so I came to view some threads on the forums to try to figure out what I was missing. I think my problem may be some general UI theory I apply in my day to day work which doesn’t make as much sense in iOS based on several of your solutions.

In general, in my UI work using other technologies, I keep view logic and model logic isolated, and tie them together with the controller. Typically the controller doesn’t have any UI logic at all (other than handling events, or telling the UI to change according to a data change). Therefore, when I was approaching the Silver Challenge, I was planning to create a new view, of which the HypnosisView would be a subview. In this new view’s code, I was planning to set the UISegementedView as a subview of the HypnosisView. Then, the new view itself would be added to the HypnosisViewController as its view. This way, the UI controls would all be in “view code” and not in the controller if that makes any sense.

However, I notice several solutions here have the code to create and add the UISegementedView right in the controller. It feels alien to me to build up UI in the controller. So my question is about which is the best practice:

  1. Create views in view files (like HypnosisView) and add it to the controller, but keep most UI creation code out of the controller?
  2. Create views in view files (like HypnosisView) and add to the controller, and also freely manipulate them by creating and adding new controls right in the controller?

I’m assuming, that later in the book when we start seeing more dynamic UIs, where controls and views are added and removed at runtime, this question will be answered in the book. Is that right?

Any thoughts you guys have on this would be appreciated.
Thanks,
Marshall