Hey all,
I am a newbie at Objective-C. I bought Cocoa Programming for Mac OS X by Hillegass a few days ago and I'm on CHAPTER 5.
There is this challenge that I'm having a hard time with. I'm supposed to display a string which would contain :
- the string entered in the text field
- the number of characters that that strings contains
in a label (text field).
Here is my code, maybe you can help me :
I commented the part where I'm having a hard time using stringWithFormat:
Can anyone give me a hand, and maybe help me make this code better (i get warnings from Xcode)
Thanks in advance
I am a newbie at Objective-C. I bought Cocoa Programming for Mac OS X by Hillegass a few days ago and I'm on CHAPTER 5.
There is this challenge that I'm having a hard time with. I'm supposed to display a string which would contain :
- the string entered in the text field
- the number of characters that that strings contains
in a label (text field).
Here is my code, maybe you can help me :
Code:
#import "AppController.h"
@implementation AppController
-(void)setStringValue:(NSString *)theString {
}
-(IBAction)countChars:(id)sender {
NSString *theString = [textField stringValue];
NSString *theResult = [theString length];
NSLog(@"The RESULT IS : %d", theResult);
int length;
if ([theString length] == 0) {
NSLog(@"la chaine de %@ est vide", textField);
[theCount setStringValue:@"Please enter something in the field !"];
}
// works fine up to here
NSLog(@"'%@' contains %d characters", theString, theResult);
// Here i want to display sthg like "blah blah blah contains 18 characters" ------
// but having a hard time with the stringWithFormat: fonction ...
// something like
// [NSString stringWithFormat:@"'%@' contains %@ characters...", theString,theResult];
}
@end
I commented the part where I'm having a hard time using stringWithFormat:
Can anyone give me a hand, and maybe help me make this code better (i get warnings from Xcode)
Thanks in advance