rops
rops

Reputation: 217

NSTextField unrecognized selectors

I have a text label declared as:

@property (weak) IBOutlet NSTextField *label;

I set some attributes in awakeFromNib method:

- (void)awakeFromNib {
    [label setStringValue:@"hello"];
}

And it all works. But when I try to change the string value (with setStringValue as well) somewhere else in the code I receive this error:

-[__NSCFString setStringValue:]: unrecognized selector sent to instance 0x105703040

I noticed it behaves the same way also with methods like isHidden, setHidden Any idea why?

Upvotes: 0

Views: 975

Answers (2)

Hot Licks
Hot Licks

Reputation: 47759

You need to learn how to read the error messages. You're being told that "setStringValue:" was "sent" to an NSString/CFString object. This means that the pointer in "label" is not an NSTextField but is instead an NSString. Most likely, at some prior point in your program, you assigned an NSString to "label" when you meant to do setStringValue or some such. Or else, since "label" isn't retained, the storage was reclaimed and then used for an NSString.

Upvotes: 1

rob mayoff
rob mayoff

Reputation: 386018

The error message is telling you that you're sending the setStringValue: message to an NSString object, not an NSTextField object. Your awakeFromNib code is fine, but your code to change the label's string is wrong.

Upvotes: 0

Related Questions