Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

glossywhite

macrumors 65816
Original poster
Feb 28, 2008
1,120
3
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
 

Attachments

  • Screen shot 2009-09-08 at 21.27.04.png
    Screen shot 2009-09-08 at 21.27.04.png
    23.8 KB · Views: 153
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?. :)

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.
 
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.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.