View Full Version : Some beginners help
jaikob
Dec 9, 2008, 11:56 PM
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:
[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
Dec 10, 2008, 12:32 AM
You should take a look at the Apple docs for NSString, plenty of useful methods in there! Two examples:
[outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];
NSString *out = [NSString stringWithFormat: @"Number: %@", [inputfield stringValue]];
[outputfield setStringValue: out];
etc.
themoonisdown09
Dec 10, 2008, 12:40 AM
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
Dec 10, 2008, 09:30 AM
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:
[outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];
It is telling me:
error: 'inputfield' undeclared (first use in this function)
themoonisdown09
Dec 10, 2008, 09:31 AM
When I use:
[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
Dec 10, 2008, 09:43 AM
In my header file it is specified like this:
- (IBAction)inputfield:(id)sender;
What do you mean by declared?
themoonisdown09
Dec 10, 2008, 09:46 AM
In my header file it is specified like this:
- (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.
jaikob
Dec 10, 2008, 05:57 PM
someone?
themoonisdown09
Dec 10, 2008, 06:06 PM
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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.