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

jaikob

macrumors 6502
Original poster
Jul 1, 2008
429
0
Freeland, MI
I am starting a cocoa objective-c application (My first). What I want to achieve is this:

I have a textbox, I want to get the value of the textbox once a button is clicked, and display it in a different textbox.

I have created an object, and specified actions for the button, and for the "inputfield". I set the "outputfield" as an outlet.

If I use this code for the button action:

Code:
[outputfield setStringValue:@"This will be outputted"];

It outputs the string defined. Well I want it to output the string in "inputfield" to the "outputfield" with the string "Number:" infront of it.

So, if I type "1234" in inputfield I want it to display "Number: 1234" in the outputfield.


I hope this is understandable.
 

BravoBug

macrumors newbie
Dec 8, 2008
26
0
Oregon, USA
You should take a look at the Apple docs for NSString, plenty of useful methods in there! Two examples:

Code:
[outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];

NSString *out = [NSString stringWithFormat: @"Number: %@", [inputfield stringValue]];
[outputfield setStringValue: out];

etc.
 

themoonisdown09

macrumors 601
Nov 19, 2007
4,319
18
Georgia, USA
I don't know if you have any books on Cocoa and Objective-C, but the book Cocoa Programming For Mac OS X by Aaron Hillegass is great for beginners. If you have XCode 3, then the third edition of the book is what you want.

I've went through this book and it really helped me understand a lot of different things that I didn't know.
 

jaikob

macrumors 6502
Original poster
Jul 1, 2008
429
0
Freeland, MI
I don't know if you have any books on Cocoa and Objective-C, but the book Cocoa Programming For Mac OS X by Aaron Hillegass is great for beginners. If you have XCode 3, then the third edition of the book is what you want.

I've went through this book and it really helped me understand a lot of different things that I didn't know.

Yeah, I'm going to purchase a book soon.

When I use:

Code:
[outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];

It is telling me:

error: 'inputfield' undeclared (first use in this function)
 

themoonisdown09

macrumors 601
Nov 19, 2007
4,319
18
Georgia, USA
When I use:

Code:
[outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];

It is telling me:

error: 'inputfield' undeclared (first use in this function)

Are you sure that you have the variable inputfield declared correctly in that function?
 

jaikob

macrumors 6502
Original poster
Jul 1, 2008
429
0
Freeland, MI
In my header file it is specified like this:

Code:
- (IBAction)inputfield:(id)sender;

What do you mean by declared?
 

themoonisdown09

macrumors 601
Nov 19, 2007
4,319
18
Georgia, USA
In my header file it is specified like this:

Code:
- (IBAction)inputfield:(id)sender;

What do you mean by declared?

Ah... never mind. I think I read it wrong. I was thinking that inputfield was a variable, not a function. Plus, I'm in C# mode right now, not Objective-C.
 

themoonisdown09

macrumors 601
Nov 19, 2007
4,319
18
Georgia, USA
If you want to download all the projects from that Cocoa book I mentioned earlier, you can download it on the book's website here:

http://bignerdranch.com/products.shtml

Under the Cocoa Programming for Mac OS X title, you should see a link that says "Get the solutions".

You can run the programs and look and see how everything works. The solutions are meant for XCode 3. Look at the project called RandomApp. It calculates a random number when you press a button, and displays the number in a text box.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.