View controllers

Discussion in 'iOS Programming' started by liptonlover, Oct 14, 2008.

  1. liptonlover macrumors 6502a

    Joined:
    Mar 13, 2008
    #1
    I'm trying to learn about view controllers, which I haven't needed so far in programming for macs, using objC/cocoa. I know I probably should have, but I didn't have to. But apparently it's pretty much required for a multi window iphone app, so I need to learn how. But the only thing I can find on the subject is an uncompleted chapter on them in pragmatic programmer's iphone dev book. Can anyone point me to a tutorial/book or something?
    Thanks, Nate
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Try the view controllers programming guide in the iPhone documentation. Also, all the Apple sample code uses view controllers.
     
  3. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #3
    I'll try Apple's docs, but me and them have a bad history. Other options would be nice.
     
  4. levous macrumors newbie

    Joined:
    Oct 8, 2008
    #4
    ...understood. I found quite a number of really poor designs watching screen casts and even in many of Apples examples. The best way to figure them out is to walk through the tutorials and review the examples. The best example for me, so far, is Apples UICatalog example.

    This guy was pretty helpful and has some strong examples
    http://iphone.zcentric.com

    My take on ViewControllers is that they are event managers for various objects that derive from or interact with UIView. Start with a UITableView tutorial and move on from there.
     
  5. detz macrumors 65816

    Joined:
    Jun 29, 2007
    #5
    I might be using them wrong but I only use them if I need rotate, other than that I see no use for them.
     
  6. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #6
    Before, I was just using different windows for various "views" but when I had code to press a button to go to the next window, while it worked fine going to that window, pressing the buttons and such in that new window didn't do anything. I was using – makeKeyAndVisible to switch to the new window. So if you can correct that problem, I don't even need a tutorial.
     
  7. detz macrumors 65816

    Joined:
    Jun 29, 2007
    #7
    Don't create new windows just create new views and swap those out from the window.

    PHP:
    UIView *view1 ....
    UIView *view2 ....

    [
    window addSubView:view1];


    -(
    IBAction)push:(id)sender{
        [
    view1 removeFromSubview];
        [
    window addSubView:view2];
    }
    The basic idea...
     
  8. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #8
    first, just want to make sure you meant to write removeFromSubview? If it's the subview of the window, then shouldn't it be removeFromSuperview?

    Also, how do you handle the various views in IB? Can I put each one in a different window just to manage laying out an interface, and still have them appear in the displayed window?

    Thanks!
    Nate
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    liptonlover, you are completely on the wrong track. Work with one of the examples that has a navbar. Using a navbar correctly requires use of view controllers.

    The navbar will manage all adding and removing of views to appear in the window.
     
  10. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #10
    The particular app I'm working on doesn't work like that... It's a game. I started looking into view controllers because of the problem I had switching windows... sorry if I sound noobish and I'm not planning on using them correctly, the idea for me right now is to learn how and why to use them.
     

Share This Page