newbie question
newbie question
- Subject: newbie question
- From: Daniel Child <email@hidden>
- Date: Fri, 12 Nov 2004 22:30:58 -1000
Hi,
I am trying to put together a (very basic) challenge problem in Hillegas's book, but it is not running properly. Basically, I have an NSTextField object in IB which is supposed to receive a string. When you press the countLettersButton, the program is supposed to count the letters in the String. Sadly, I can't get that much to work, though I can reset fields to empty and 0 using the StartOver button I created. Here the critical parts of code.
@interface MyDocument : NSDocument
{
// INSTANCE VARIABLES
int numLetters;
NSString *whatUserTyped;
NSString *theLength;
// IBOUTLETS
IBOutlet NSButton *countLettersButton;
IBOutlet NSButton *startOverButton;
IBOutlet NSTextField *theStringToCount; // where user inputs a string
IBOutlet NSTextField *theAnswer; // where the answer comes back
}
// ACTION METHODS
- (id)sender;
- (id)sender;
// PRIVATE METHODS
- (void)updateUI;
@end
And the rest of it is as follows:
- (id)init
{
self = [super init];
if (self)
{
whatUserTyped = [[NSString alloc] init];
theLength = [[NSString alloc] init];
numLetters = 0;
}
return self;
}
- (id)sender
{
whatUserTyped = [theStringToCount stringValue];
numLetters = [whatUserTyped length];
theLength = [NSString stringWithFormat: @"%d", numLetters];
[self updateUI];
}
- (id)sender
{
whatUserTyped = @"";
numLetters = 0;
theLength = [NSString stringWithFormat: @"%d", numLetters];
[self updateUI];
}
- (void)updateUI
{
[theStringToCount setStringValue: whatUserTyped];
[theAnswer setStringValue: theLength];
}
(There are some automatically included methods that I'm leaving out since they are standard.) The interface looks OK, but when I click on countLettersButton, the answer field is set to 0. At the same time, the cursor in the entry field indicates that there are invisible letters there, and if you highlight them, the original letters reappear, but only if highlighted. Clearly, something is wrong with the countLetters method, as well as with something else which messes up the display. I've wasted a bunch of time on this and would appreciate any help. Thanks!
Daniel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden