Some Xcode help needed.

Discussion in 'Mac Programming' started by Mettra, Mar 24, 2009.

  1. Mettra macrumors newbie

    Mar 24, 2009
    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!
  2. MrFusion macrumors 6502a

    Jun 8, 2005
    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.

Share This Page