Old Xcode and 3.0

raydot

Registered
Hi,

I'm following the XCode tutorials on O'Reilly's macdevcenter.com, specifically:

http://www.macdevcenter.com/pub/a/mac/2002/01/04/cocoa.html

On page four of that tutorial it discusses adding sliders, and then modifying the sliders NIB file in Interface builder to generate classes which can then be modified.

My problem: This tutorial was written over six years ago -- that's 42 in developer years -- and I can't figure out how to do this with a more recent version. From the middle of page four, just under the graphic, where the author writes: "I have configured the sliders such that they are small..." to the bottom, I can't figure it out in XCode 3.0.

The attributes editor seems completely different than what's pictured here. Any suggestions?
 
The process for creating classes has changed significantly with XCode and Interface Builder 3.0. You no longer generate classes within Interface Builder. Instead, you create your classes "by hand" in XCode, and then import them into IB by dragging the .h files into your nib's window. From that point on, any changes you make to the class in XCode will automatically be mirrored in Interface Builder.

So, the new process should go something like this:

- In XCode, select File > New, and choose "Cocoa > Objective-C class".
- Name it "AnimationController", as in the example you linked.
- Add actions by typing them in. Here is an example of a new class with one custom action:
Code:
#import <Cocoa/Cocoa.h>

@interface AnimationController : NSObject {
	
}
- (IBAction)changeXSpeed:(id)sender;
@end
- Save changes to your new .h file and drag it into the main window of your nib in Interface Builder to import it.

Instantiating classes in Interface Builder has also changed a lot. It now goes a little something like this:

- In IB's Library palette, under "Objects and Controllers", drag an NSObject (the first item, which looks like a blue cube) into the nib's main window (where your windows and things are).
- Select it and open the Identity Inspector (under the tools menu).
- In the "Class" field in the inspector, type in "AnimationController" to change the object's class. Now you should have access to the actions you created.

The rest should be basically the same as in previous versions, so I think those tutorials will serve you well.


In my opinion, using Interface Builder has always been one of the biggest hurdles to learning to program with Cocoa, and Interface Builder 3.0 made it an even bigger hurdle. There's certainly a learning curve with Interface Builder, which can be a shock for people accustomed to Apple's usual intuitive interface design. The good news is that once you understand the basics of IB, it's not hard to use (at least most of the time). I hope my instructions help. If you have more questions, ask away.
 
Mikuro,

I've asked this question in a few places and you're the first person to reply at all, thanks. I haven't tried your response yet, but I will and I'll get back to you.

In the mean time I do have one question:

Code:
#import <Cocoa/Cocoa.h>

@interface AnimationController : NSObject {
     //WHAT THE HECK IS THIS?	
}

@end

What goes in that spot I marked above? Function calls? Procedures for all Animation Controller objects? ?
 
That space is for the instance variables. i.e., the properties of each individual object of that type. So if you wanted to you wanted to add, say, a framerate variable to each AnimationController, you could do it like this:

Code:
#import <Cocoa/Cocoa.h>

@interface AnimationController : NSObject {
     int fps;
}

@end
 
Welcome back. :)

Constructors are the functions you make to initialize a new object. Say you have a bunch of instance variables, like framerate or whathaveyou. If you want these variables to have meaningful values when you make a new object, you need to have some code that runs whenever a new object is created. That's the constructor -- a method that's called whenever you make a new instance of that class.

You know how whenever you make a new object in Objective-C, you need to do something like [[someClass alloc] init]? init is the constructor. People use the word "constructor" more when dealing with C++ than Objective-C, but whatever you call it, it's basically the same idea -- code that runs when the object is first created.

A basic Objective-C initializer/constructor looks like this (in your .m file):
Code:
- (id)init {
	if ( self=[super init] ) {
		//do something here
	}
	return self;
}
 
I see now. Instance variables for the AnimationController...

Do you know of any good (better) graphics tutorials online?!
 
I asked you a longish question here, but in asking it I figured it out.

So now there just seems to be no control over the ball using the sliders. I know you don't have my code files, but any idea what I might be doing wrong? Is it an IB issue or a code issue?! I'm having trouble seeing how AnimationView and AnimationController work together?

Thanks,

Dave.
 
Last edited:
I don't have your code, but I can hazard a guess that you need to connect objects in Interface Builder to the appropriate actions and outlets. If you want a slider control to do something, control-drag in Interface Builder from the slider to the object you want it to control, and select the method you want it to call.

If you have IBOutlets in your .h files, you also need to connect them in Interface Builder, otherwise anytime you try to use them in your code, nothing will happen. Again, you need to control-drag in IB, this time from the object with the outlet to the object you want that outlet to point toward.

You may need to instantiate AnimationController in IB in order to connect it to other objects. I explained that a bit in my first reply here.

Just a guess.
 
Back
Top