Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Changing Label with Button Press

TheDogTheDog Posts: 25Registered Users
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
Post edited by TheDog on

Replies

  • DomeleDomele Posts: 2,948Registered Users
    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

    - (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/objective-c/the-basics-of-protocols-and-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
  • TheDogTheDog Posts: 25Registered Users
    Thanks! Is there a different way if I do not mind losing the Color Picker?
  • DomeleDomele Posts: 2,948Registered Users
    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
Sign In or Register to comment.