Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
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
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Try the view controllers programming guide in the iPhone documentation. Also, all the Apple sample code uses view controllers.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
I'll try Apple's docs, but me and them have a bad history. Other options would be nice.
 

levous

macrumors newbie
Oct 8, 2008
6
0
I'll try Apple's docs, but me and them have a bad history. Other options would be nice.

...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.
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
I might be using them wrong but I only use them if I need rotate, other than that I see no use for them.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
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.
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
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.

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...
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
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
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.