tags:

views:

72

answers:

2

I'm trying to make a simple Cocoa application using the newest version of XCode. In interface builder I added NSTextField and NSButton. When I press the button, I want it to clear whatever is in the text field.

I made a new class called AppController.h. This is the contents:

#import <Foundation/Foundation.h>


@interface AppController : NSObject {
    IBOutlet id textView;

}

- (IBAction) clearText: sender;
@end

AppController.m looks like this:

#import "AppController.h"


@implementation AppController

- (IBAction) clearText: sender 
{ 
    [textView setString: @" "]; 


} 
@end

I connected the button to clearText and the textbox to textView.

The program compiles and runs. But when I press the button, nothing happens. Why is that?

+1  A: 

This is very basic. I suggest you google for some tutorials. There's plenty out there. Here's something that may help. Chapter 8 describes how to do exactly what you're asking. link text

regulus6633
I tried following that tutorial, but I can't because it looks like it was made for an older version of Xcode.
Phenom
If you can't follow that tutorial then do as I suggested and google for other tutorials. I'm sure you'll find something you like.
regulus6633
That's what I've been doing. All the tutorials I find are for older versions of xcode. What I was trying to do also comes from such a tutorial.
Phenom
+1  A: 

here's the run down. 1.Create an IBAction in your appController class header.

- (IBAction)someMethod:(id)sender;

2.Then create an IBOutlet for you text field

 IBOutlet NSTextField *textFieldname;

You then connect the IBAction to the button in interface builder, and your IBOutlet to your textfield.

Inside the implementation file (.m) IBAction method do

- (IBAction)someMethod:(id)sender{
 textFieldname.stringValue = @"";
}
ghostsource
Seems to make sense, but I tried this, and it doesn't work.
Phenom
Send me your xcode project.
ghostsource