Changing text on a button

Discussion in 'iOS Programming' started by Moon013, Jul 23, 2008.

  1. Moon013 macrumors newbie

    Jul 14, 2008
    Anyone knows how to change the text permanently on a rounded rect button upon clicked?
  2. ethana macrumors 6502a

    Jul 17, 2008
    Seattle, WA
    Would you just change the "title" property on a touch event?

    btnFoo.title = @"new text";

    Correct me if I'm wrong?

    You can learn how to capture events from buttons by just looking at some of the sample Projects on the SDK site.

  3. Sbrocket macrumors 65816


    Jun 3, 2007
    [myButton setTitle:@"Normal title" forState:UIControlStateNormal];
    [myButton setTitle:@"Pressed title" forState:UIControlStateHighlighted];
  4. ethana macrumors 6502a

    Jul 17, 2008
    Seattle, WA
  5. Moon013 thread starter macrumors newbie

    Jul 14, 2008
    Firstly, thanks for helping!

    And sadly, It doesn't work for me..

    This is the code:

    [button setTitle:mad:"Finish" forstate: UIControlStateHighlighted];

    I put it in a function, which will trigger when button is clicked. It can run the program, but it doesn't change the text. Oh yeah, thats a warning to that line of code:

    "UIButton" may not respond to "-setTitle:forstate"

    And forgive me, I wasn't clear on my question, what I meant is when I clicked the button, the text will be changed permanently... Is that possible to do that? The codes in the header files doesn't look like doing this kind of thing...
  6. Moon013 thread starter macrumors newbie

    Jul 14, 2008
    Again, sorry. I actually forgot to write IBOutlet when declaring a button, thus cannot link. Now, it works like a charm!

    Sorry and thanks for the help!:)
  7. RobertMartens macrumors 65816


    Aug 29, 2002
    Tokyo, Japan
    Two Years Later

    I just found this answer and used it

    Thanks from the future.
  8. cnstoll macrumors 6502

    Aug 29, 2010
    I also found this in the future, but I'm going to have to bring the past back to life because it didn't work for me :(

    I've made a simple stopwatch with a start/stop button, and what i'm trying to do is change the stop button to stay "reset" after it's clicked once, and revert back to "stop" when the stopwatch is running.

    The solution in this thread is pretty much exactly how I'd written my code. I defined an IBOutlet UIButton in my header file. I hooked up the outlet in interface builder. And in a few places in the code I call setTitle and pass it UIControlStateNormal, because I just want it to change the normal non-highlighted/selected state.

    It's not working and I really have no idea why. Something that did occur to me as I was writing this is that I did set the initial title for the button in interface builder. Could that have something to do with it?

    Anyways, sorry to resurrect a dinosaur, but this seemed a good place to post my problem.
  9. cnstoll macrumors 6502

    Aug 29, 2010
    I figured out my problem and it was basically a total brain fart on my part. Everything here is working just fine.
  10. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Care to clue us in as to what the issue was, so we can try to avoid our own brains farting in this way? ;)
  11. cnstoll macrumors 6502

    Aug 29, 2010
    Heh, I almost posted it but I was embarassed.

    For some reason I had set the button = nil in my viewDidLoad method. I think I had done that and then had some configuration of the button properties after that at one point and I deleted the properties and just set the title and font and all that in interface builder, but apparently I didn't delete the "buttonName = nil" part.

    So yea, message to all you future searchers...don't set your buttons equal to nil :(

Share This Page