iPhone - Views and controllers

Discussion in 'Mac Programming' started by rand0m3r, May 8, 2008.

  1. rand0m3r macrumors regular

    Jun 30, 2006
    if u've had some iphone experience, can i ask you a question. how is the model-view-controller paradigm implemented now? i'm a bit confused because i've been following some examples where everything was done programmatically, and some examples where an incomplete IB is used (current betas).

    basically, if ur application has more than one view, what do u do? at first i thought u had one controller, and then used it to control the view hierarchy, using the method addSubview.

    now, i get the impression that you should use a controller for each view.

    i've been trying to implement a UITextView. but the fact that it hasn't been implemented in IB yet makes it annoying, i tried to paste some code from the iphone dev center but it didn't work at all :(
  2. lucasgladding macrumors 6502

    Feb 16, 2007
    Waterloo, Ontario
    Check out the SimpleDrillDown or SQLiteBooks if you need examples. You may not be able to copy and paste the code, but you're not going to be able to build much with copy and paste anyway. Think of each "screen" as a window. A view controller should exist for each window. If there are multiple windows, you need to look at navigation or tab controllers.

    You should be going through Cocoa programming books if you're not sure about how MVC is implemented with the Mac OS or the iPhone OS. The concepts are very, very similar between the two systems. http://cocoadevcentral.com/ is a great place to start if you are new to development on the Mac.

    The iPhone OS Programming Guide should be read before doing anything with the SDK. Specifically, the section "Using View Controllers with Views" answers your question.

    Interface Builder doesn't really have anything to do with how you preserve the MVC pattern. The basic idea has stayed the same since the first release of the SDK. IB simply makes it easier to create some of the elements.

    Best of luck
  3. Duke Leto macrumors regular

    Mar 17, 2008
    I would also recommend looking at the SimpleDrillDown App, but if you are using you application to store data, I would also learn to use SQLite in your code. I recently had a stressful weekend of exchanging all of my arrays and hardcoded data into data written to an SQLite database.

    For resources look at:
    SQLite Books (sample code).

    I wish you the best of luck making an application :)

Share This Page