# [_outlet setString:@"testing"]; // selector not recognized



## retrotron (May 29, 2004)

I can't seem to reference an NSTextField. I've got to be missing something obvious. 

So in Interface Builder I create a single textfield in the window, create a controller class with one outlet named '_outlet' of type NSTextField. I instantiate the class, control-drag from the controller instance to the textfield and connect the '_outlet' outlet. I generate the controller class file, then add an -awakeFromNib method and try to do this: [_outlet setString"testing"]. But the application crashes and the error is that the selecter to [-NSTextField setString] is not recognized. What am I doing wrong?

Here's the .h and .m file:


```
// header file

#import <Cocoa/Cocoa.h>

@interface TextfieldOutputController : NSObject
{
    IBOutlet NSTextField *_outlet;
}
- (void)awakeFromNib;
@end

// implementation file
#import "TextfieldOutputController.h"

@implementation TextfieldOutputController

- (void)awakeFromNib {

  [_outlet string];

} // end awakeFromNib

@end
```


----------



## retrotron (May 29, 2004)

Maybe I just figured it out. If I use the -setStringValue: method instead of -setString: it works. I must have been looking at the wrong doc page. Anyways, can someone explain why the wrong method crashes the program? I would have thought it would just tell me no method responds to the message, but instead it doesn't recognize the selector, and I'm not sure why.


----------



## btoth (May 29, 2004)

Well, it doesn't ignore the method if some subclass of the object recognizes it.  I really don't understand what setString: does by looking at the documentation.  Just remember to use setStringValue: with controls I guess. 

It would be nice if XCode's objective-c code suggestions where on the level of Visual Basic's in that it wold first list the class methods for the referenced object and not every single method that it's subclasses might comply to.  It's not usually helpful when an object dumps out all the methods that NSObject responds to. 

** Edit **

Sorry, I read your error wrong.  I don't know why your program crashed because of it since I really don't know how it all works behind the scenes.  My guess would be that it was a memory error or something.


----------



## retrotron (May 30, 2004)

Yeah, I guess the answer is to use -setStringValue: for controls.


----------



## anarchie (May 30, 2004)

setString: is for NSText, which is the class used for an NSTextField's field editor while it is being edited, and for the NSText subclass NSTextView which can display and edit styled text as in TextEdit.

Look up Exception Handling.  An exception is raised when an object is sent a message it does not respond to.  When debugging your program, be sure to manually enter a symbolic breakpoint on _NSRaiseError via the Breakpoints palette.  This is the function through which all exceptions are raised, and becomes a great aid in debugging.


----------

