Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 24, 2009, 02:59 AM   #1
Mettra
macrumors newbie
 
Join Date: Mar 2009
Some Xcode help needed.

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!
Mettra is offline   0 Reply With Quote
Old Mar 24, 2009, 03:45 AM   #2
MrFusion
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
Quote:
Originally Posted by Mettra View Post
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.
MrFusion is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
The App Store app thinks Xcode is installed, but I deleted Xcode. moonman239 Mac Applications and Mac App Store 3 May 6, 2014 05:53 PM
Moving from xcode 3.2 to xcode 4.5.2 compilation error for 'abs' macro in stdlib.h hrishidev Mac Programming 7 Jun 2, 2013 10:36 AM
Xcode 3 vs Xcode 4 when dealing with Objective-C timebourne Mac Programming 8 Sep 23, 2012 05:36 PM
XCode 4.4.1 to Xcode 4.5 in Mountain Lion VinegarTasters OS X 10.8 Mountain Lion 2 Sep 19, 2012 08:55 PM

Forum Jump

All times are GMT -5. The time now is 08:42 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC