So I have all this code that I have debugged and it seems to be fine. I made a mutable string and for some reason I can not get it to be displayed on my label. the debugger says
“2010-04-22 22:50:26.126 Fibonacci[24836:10b] *** -[NSTextField setString:]: unrecognized selector sent to instance 0x130150”
What is wrong with this? When I just send the string to NSLog, it comes out fine.
here’s all my code, any help would be appreciated. “elementNum” is a comboBox and “display” is a Label.
Thanks
#import "Controller.h"
@implementation Controller
- (IBAction)computeNumber:(id)sender {
int x = 1;
int y = 1;
NSMutableString *numbers = [[NSMutableString alloc] init];
[numbers setString:@"1, 1,"];
int num = [[elementNum objectValueOfSelectedItem]intValue];
int count = 1;
while (count<=num) {
int z = y;
y+=x;
x=z;
[numbers appendString:[NSString stringWithFormat:@" %d,", y]];
count++;
}
[display setString:numbers];
NSLog(numbers);
}
@end
`
Look at the error message you’re getting:
This is telling you something. Specifically, that
NSTextFielddoes not have a-setString:method and trying to call it will fail.This is your cue to look at the docs for
NSTextField. When you do so, you will see that there are no methods to set the string value. However, the docs also show you thatNSTextFieldinherits fromNSControl, which has a-setStringValue:method.So, you need to call
-setStringValue:to set the value of anNSTextField.Note that in your code at present, you are leaking the
numbersstring object. You created it using-alloc, so you are responsible for releasing it.Instead, you should create it using
[NSMutableString stringWithString:@"1, 1,"], which will return an autoreleased object, as well as initializing it in the same message.