PDA

View Full Version : Some Xcode help needed.




Mettra
Mar 24, 2009, 02:59 AM
Here is my program, I have a label, an input text field, and a button. I want to type in some text in the input field, and when I click the button, have the label display the text.

I just can't get this to work I got - (IBAction)Press:(id)sender {
[Display setStringValue:@"Hello World"];
}


But I have no clue what to do for the input field...

This is probably child's play for most people, but I am extremely new to this so any and all help Is appreciated!



MrFusion
Mar 24, 2009, 03:45 AM
Here is my program, I have a label, an input text field, and a button. I want to type in some text in the input field, and when I click the button, have the label display the text.

I just can't get this to work I got - (IBAction)Press:(id)sender {
[Display setStringValue:@"Hello World"];
}


But I have no clue what to do for the input field...

This is probably child's play for most people, but I am extremely new to this so any and all help Is appreciated!

It's probably something like this


NSSTring * str = [input getValue]; //or getString, or ... (see docs)
[label setStringValue:str];



However, this is much nicer, cooler way to do this.
Add a NSString *str instance in the header of your class. Bind the value of both the input text field and the label to str. Your label will change automatically without the need for a button. It's called KVC (key value coding). Very useful to learn.
If you want to change the input before displaying it, you overwrite the set and get functions of KVC. Read up about KVC for more information


-(NSString *) getStr;
-(void) setStr:(NSString *) value;



Unless of course, the user needs to explicit take action. Then you still need the button.