Cocoa and Xcode Question

Discussion in 'Mac Programming' started by kashmoney2006, Mar 26, 2008.

  1. macrumors regular

    Joined:
    Dec 12, 2007
    #1
    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:
    Code:
    @interface TicTacToeController : NSObject {
    	
    	IBOutlet NSTextField *text00;
    
    }
    
    - (IBAction)setText: (id)sender;
    
    and
    Code:
    @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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You can use NSLog() for some simple debugging (which shows up in the Run > Console window):

    Code:
    - (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.
     
  3. thread starter macrumors regular

    Joined:
    Dec 12, 2007
    #3
    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
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     

Share This Page