Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mettra

macrumors newbie
Original poster
Mar 24, 2009
9
0
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
Code:
- (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!
 
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
Code:
- (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

Code:
 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

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

Unless of course, the user needs to explicit take action. Then you still need the button.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.