setTitle - trying to set title of an NSWindow to contents of NSTextfield - failing

Discussion in 'Mac Programming' started by glossywhite, Sep 8, 2009.

  1. glossywhite macrumors 65816

    glossywhite

    Joined:
    Feb 28, 2008
    #1
    I'm just starting to get the hang of Obj-C but I can't get this to work - set the title of the window to the contents of the text field. Where am I slipping up, please?. :)

    here is my code:

    header
    Code:
    //
    //  controller.h
    //  SetWindowTitleToTextBox
    //
    //  Created by Matt Foot on 08/09/2009.
    //  Copyright 2009 __MyCompanyName__. All rights reserved.
    //
    
    #import <Cocoa/Cocoa.h>
    
    
    @interface controller : NSObject {
    	IBOutlet NSWindow *myWindow;
    	NSTextField *myTextfield;
    
    }
    -(IBAction)changeTitle:(id)sender;
    @end
    
    main
    Code:
    //
    //  controller.m
    //  SetWindowTitleToTextBox
    //
    //  Created by Matt Foot on 08/09/2009.
    //  Copyright 2009 __MyCompanyName__. All rights reserved.
    //
    
    #import "controller.h"
    
    
    @implementation controller
    -(IBAction)changeTitle:(id)sender{
    	[myWindow setTitle:[myTextfield stringValue]];
    }
    
    @end
    
     

    Attached Files:

  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    I can see two immediate problems:

    1. You haven't explained how it doesn't work.

    2. myTextfield isn't an IBOutlet, so it's almost certain that it's nil at the time changeTitle: is invoked.
     
  3. glossywhite thread starter macrumors 65816

    glossywhite

    Joined:
    Feb 28, 2008
    #3
    Yes you're right - I am sorry, fancy not mentioning the error - I am a fool!. However, I have solved this, and the problems were what you said, and also I hadn't dragged controller object to NSTextfield.

    Thanks so much! :D
     

Share This Page