PDA

View Full Version : Cocoa and Xcode Question




kashmoney2006
Mar 26, 2008, 03:59 PM
I have set up a NSTextfield object and NSButton object and placed both of them on the application window using Interface Builder. I then connected the text field to text00 and the button to setText:

here is my code:

@interface TicTacToeController : NSObject {

IBOutlet NSTextField *text00;

}

- (IBAction)setText: (id)sender;


and

@implementation TicTacToeController

- (IBAction)setText: (id)sender {

[text00 setStringValue:@"X"];

}


what i am trying to do is, have the text field display an X when the button is pushed. but, when i run the program in the simulator in IB and push the button, nothing happens. can anybody help me out? all input is appreciated. Thanks.



kainjow
Mar 26, 2008, 05:11 PM
You can use NSLog() for some simple debugging (which shows up in the Run > Console window):

- (void)awakeFromNib {
NSLog(@"text00: %@", text00);
}

- (IBAction)setText: (id)sender {
NSLog(@"sender: %@", sender);
[text00 setStringValue:@"X"];
}

If you see "(null)" for text00, then that means text00 isn't properly connected in IB. If you don't see the "sender" log, then that means your button's IBAction isn't properly connected.

kashmoney2006
Mar 26, 2008, 05:23 PM
You can use NSLog() for some simple debugging (which shows up in the Run > Console window):

- (void)awakeFromNib {
NSLog(@"text00: %@", text00);
}

- (IBAction)setText: (id)sender {
NSLog(@"sender: %@", sender);
[text00 setStringValue:@"X"];
}

If you see "(null)" for text00, then that means text00 isn't properly connected in IB. If you don't see the "sender" log, then that means your button's IBAction isn't properly connected.

Thanks. I got it to work. Is there any way to set up the console to pop up everytime I run the app? or do i have to keep going to Run->Console to bring up the console window

kainjow
Mar 26, 2008, 06:27 PM
It should stay open once it's open, and even re-open when you open the project if it was open when you closed the project.