Thursday, August 25, 2011

XCode 4 - another try

After getting a pass on fussing with the Android app for at least a day, I suddenly have a window of time to get moving on the IOS app again. I finally remembered to download XCode 4 before I went to Panera, so I should have a new version to try in downloads. Let's check it out.

Ah, it's there - and seems to be verifying ok.

It seems to have installed. Let's bring it up.

Ok, apparently it's in /Developer/Applications.

Well, I mistakenly dragged it onto the icon bar, and it replaced the old xCode icon, for which I can no long find the app. Well, I guess I could if I really needed to. Let's try to sink or swim with this one for now.

It looks good. Ok, I've managed to locate open the old xcode3 prototype project. It's a very nice look. But - how to bring up the interface builder?

Ok, I can just click on the .xlb file and it comes up. That's handy.

The big question is - how do I change the the first view called to answer controller?

O.k., I tried changing it in the main view - it had something pointing to root controller - but only succeeded in blanking it out. And now, of course, the program is crashing.

Hmm...this is the part I've understood least - the connection between the view and the nav controller and the view controller.

Ok - let's go to a backup. Ok. Hmm...the selected target isn't valid when I try to run it. Close Xcode, re-open, and run, this time with the selected target as "JlptQuizApp".

And it works on the emulator. Good.

Ok, IIRC, with the xlb, you connected fields displayed on the view with fields in the header file. So, where is the *view* for questions?

Looks like it's in resources, rootcontroller.xlb, view, table view.

We actually have three main classes which deal with the UI. These are:

QuizAppDelegate
RootController
AnswerController

The QuizDelegate looks like this:


#import

@class RootController;
@class Question;
@class AppState;

@interface QuizAppDelegate : NSObject {
UIWindow *window;
RootController *viewController;
UINavigationController *navController;
Question *currentQuestion;
AppState *appState;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RootController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@property (nonatomic, retain) Question *currentQuestion;
@property (nonatomic, retain) AppState *appState;

@end



So, it has three connections with the view: UIWindow, which must be a sort of "master" window; the RootController - which the controller for the first view delegated to; and the UINavigationController. Why does it need a reference to the root controller?

Ah, here we go:



navController.viewControllers = [NSArray arrayWithObject:viewController];

[window addSubview:navController.view];
[self.window makeKeyAndVisible];



So, from the code, it's adding the RootController (i.e. th question controller) to the UINavigationContoller's array of controllers. Then, it's adding the navController's view to the main window's view.

So, we could change this to a different view, which could in turn pass control (using the code above) to the "RootController", which would no longer be the "root" or original navigation controller.

So, my objective is to create an initially *very simple* view, which will just have say one button, and said button will then pass control to the question view.

Ok, now, the question is, how to gracefully get this done? The part that concerns me is the disconnecting of the root controller and re-attachement of the main delegate to the new "start" controller.

I'll procrastinate on that until my next post!




No comments:

Post a Comment