Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-11-2011, 06:48 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 25
TheDog is on a distinguished road
Default Changing Label with Button Press

Hello all,

I just created my first basic app and am looking to build upon it. I currently have a homepage with 2 buttons: A button saying "Say Hi" and a settings button. The "Say Hi" button shows a label which has the string "Hello World" on it. The Settings button takes you to another view. This view allows you to choose a color such as red or blue. Once you choose the color, you are taken back to the main page. Then, when you press "Say Hi" the string changes to the appropriate color.

Now I was wondering how I could code a button on the settings page to change the content of the label. So after pressing the button on the settings page you are taken back to the home page after which you press "Say Hi" and the string changes its content not color.

I am really stuck here as I am still fairly new to iPhone programming. Any help would be greatly appreciated.

Thanks,
TheDog
TheDog is offline   Reply With Quote
Old 08-11-2011, 06:58 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

I think the best way to do this would be to create a protocol. Pro: It would allow you to reuse your color picker. Con: In my experience, noobs don't like to touch them with a 10 foot pole.

Basically, a protocol is a list of methods. These methods can be marked required or optional. Your settings page would have a delegate property. When the user leaves your settings page, your settings page would inform the delegate of the color the user chose through a method call. Something like
Code:
- (void)colorPickerDidFinishWithColor:(UIColor *)chosenColor;
Edit: Here is a link that explains delegates/protocols further and shows you how to implement it all: http://iphonedevelopertips.com/objec...delegates.html
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 08-11-2011 at 07:01 AM.
Domele is offline   Reply With Quote
Old 08-11-2011, 07:06 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 25
TheDog is on a distinguished road
Default

Thanks! Is there a different way if I do not mind losing the Color Picker?
TheDog is offline   Reply With Quote
Old 08-11-2011, 07:10 AM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Yes but in the long run, you'd save more time writing good code. It'll allow you to easily reuse your objects in later projects. Plus when you want to add or remove something, it's not a pita.

The quick and dirty really bad way (read: avoid, try to never ever use) would be to set a UIColor property in your 1st controller. Present the settings view controller as a modal view. Then when the user clicks done, reference the 1st view controller by using the parentViewController property of your view controller, and set its UIColor property.

But really since you are learning, why learn how to do it the wrong way? If you are learning, your focus should not be how to do something the quickest, it should be writing clean code and understanding how it works.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 08-11-2011, 07:12 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 25
TheDog is on a distinguished road
Default

Ok thanks!
TheDog is offline   Reply With Quote
Reply

Bookmarks

Tags
button, change, changing label, label, press

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
13 members and 383 guests
7twenty7, chiataytuday, cristofercolmbos, dedeys78, dre, fiftysixty, gmarro, jimmyon122, jonathandeknudt, pungs, raymng, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0