How do you add class outlets in Xcode 3?

I'm working on a tutorial that I found and are wondering on how to add class outlets like in this photo of the tutorial ( http://dl.dropbox.com/u/3783094/Screen%20shot%202011-02-23%20at%2012.57.44%20PM. png ) How would I do that in Xcode 3?

iMac, Mac OS X (10.6.4), Mac Mini/MacBook Pro

Posted on Feb 23, 2011 10:00 AM

Reply
17 replies
Sort By: 

Feb 23, 2011 11:29 AM in response to paniclabs

Open Interface Builder's Library window and click the Classes tab. For more detailed information, read the following:

http://meandmark.com/blog/2009/09/interface-builder-3-2-outlets-and-actions/

The screenshot in the article is out of date. In the most recent versions of Interface Builder, there is a pop-up menu instead of tabs for Lineage, Destination, Outlets and Actions.
Reply

Feb 23, 2011 12:28 PM in response to paniclabs

You have to get your outlets and actions into Xcode for your project to build. There are two ways to accomplish this.

1. Write your outlets and actions in Xcode.
2. Create class files from Interface Builder by choosing File > Write Class Files.

For a brand new class, either option is acceptable. If you've already written code for your class, use Xcode to add your outlets and actions. Writing class files from Interface Builder will overwrite the code you wrote.
Reply

Feb 23, 2011 12:57 PM in response to paniclabs

If you choose File > Write Class Files in Interface Builder, Interface Builder creates a .m file and a .h file.

The person who wrote the tutorial is the best person to contact about your project not working. He or she would know more than me on what needs to be done to get your project working.
Reply

Feb 23, 2011 1:15 PM in response to paniclabs

I haven't used Aquatic Prime.

To answer your question on how to add an outlet named textView and an action named validate, I have to ask a question. Do you have a .m and a .h file in the Xcode project for the class where you're adding the outlet and action? If not, you can choose File > Write Class Files in Interface Builder to create the .m and .h files.

If you do have a .m and .h file, add the outlet and action in the .h file in Xcode. The outlet looks something like the following:

IBOutlet NSTextView* textView;

And the action looks something like the following:

- (IBAction)validate:(id)sender;

Write the code for the validate: action in the .m file
Reply

Feb 23, 2011 1:28 PM in response to Mark Szymczyk

Okay did, but I'm getting two more errors from the original two. It's displaying that there are two declarations from the interface builder "NSTextView".

Here's what I have currently in the .h file (NSTextView.h)


#import <Cocoa/Cocoa.h>
@interface NSTextView : NSText {
 IBOutlet NSTextField *textView;
}
- (IBAction)deleteBackward:(id)sender;
- (IBAction)insertBacktab:(id)sender;
- (IBAction)insertNewLine:(id)sender;
- (IBAction)insertParagraphSeparator:(id)sender;
- (IBAction)insertTab:(id)sender;
- (IBAction)loosenKerning:(id)sender;
- (IBAction)lowerBaseline:(id)sender;
- (IBAction)moveBackward:(id)sender;
- (IBAction)moveDown:(id)sender;
- (IBAction)moveForward:(id)sender;
- (IBAction)moveLeft:(id)sender;
- (IBAction)moveRight:(id)sender;
- (IBAction)moveUp:(id)sender;
- (IBAction)orderFrontSubstitutionsPanel:(id)sender;
- (IBAction)raiseBaseline:(id)sender;
- (IBAction)tightenKerning:(id)sender;
- (IBAction)toggleAutomaticDashSubstitution:(id)sender;
- (IBAction)toggleAutomaticDataDetection:(id)sender;
- (IBAction)toggleAutomaticSpellingCorrection:(id)sender;
- (IBAction)toggleAutomaticTextReplacement:(id)sender;
- (IBAction)toggleBaseWritingDirection:(id)sender;
- (IBAction)toggleTraditionalCharacterShape:(id)sender;
- (IBAction)turnOffKerning:(id)sender;
- (IBAction)turnOffLigatures:(id)sender;
- (IBAction)useAllLigatures:(id)sender;
- (IBAction)useStandardKerning:(id)sender;
- (IBAction)useStandardLigatures:(id)sender;
- (IBAction)validate:(id)sender;
@end


Here's what I have currently in the .m file (NSTextView.m)


#import "NSTextView.h"
@implementation NSTextView
- (IBAction)deleteBackward:(id)sender {
 
}
- (IBAction)insertBacktab:(id)sender {
 
}
- (IBAction)insertNewLine:(id)sender {
 
}
- (IBAction)insertParagraphSeparator:(id)sender {
 
}
- (IBAction)insertTab:(id)sender {
 
}
- (IBAction)loosenKerning:(id)sender {
 
}
- (IBAction)lowerBaseline:(id)sender {
 
}
- (IBAction)moveBackward:(id)sender {
 
}
- (IBAction)moveDown:(id)sender {
 
}
- (IBAction)moveForward:(id)sender {
 
}
- (IBAction)moveLeft:(id)sender {
 
}
- (IBAction)moveRight:(id)sender {
 
}
- (IBAction)moveUp:(id)sender {
 
}
- (IBAction)orderFrontSubstitutionsPanel:(id)sender {
 
}
- (IBAction)raiseBaseline:(id)sender {
 
}
- (IBAction)tightenKerning:(id)sender {
 
}
- (IBAction)toggleAutomaticDashSubstitution:(id)sender {
 
}
- (IBAction)toggleAutomaticDataDetection:(id)sender {
 
}
- (IBAction)toggleAutomaticSpellingCorrection:(id)sender {
 
}
- (IBAction)toggleAutomaticTextReplacement:(id)sender {
 
}
- (IBAction)toggleBaseWritingDirection:(id)sender {
 
}
- (IBAction)toggleTraditionalCharacterShape:(id)sender {
 
}
- (IBAction)turnOffKerning:(id)sender {
 
}
- (IBAction)turnOffLigatures:(id)sender {
 
}
- (IBAction)useAllLigatures:(id)sender {
 
}
- (IBAction)useStandardKerning:(id)sender {
 
}
- (IBAction)useStandardLigatures:(id)sender {
 
}
- (IBAction)validate:(id)sender {
 
}
@end



.... Most of the code came from what was already in the outlets and the actions came through IB.
Reply

Feb 23, 2011 1:45 PM in response to paniclabs

NSTextView is part of the Cocoa framework. You can't create your own files called NSTextView.h and NSTextView.m. You need to create your own class and add the textView outlet and the validate action to that class. Choose File > New File in Xcode to create your own class file. Select Cocoa Class under Mac OS X. Select Objective-C Class, and make it a subclass of NSObject.
Reply

Feb 23, 2011 2:13 PM in response to paniclabs

Did you make the necessary connections in Interface Builder? You need to make a connection from File's Owner to the text field for the textView: outlet. You also need to make a connection to set the validate: action.

Another thing to check is the capitalization of textView. You declared it as textView in the header, but the error message you listed spelled it as textview. The names textView and textview are not identical, and can cause syntax errors.
Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do you add class outlets in Xcode 3?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.