views:

8160

answers:

1

I have a UIButton, that when pressed, brings up a new view where the user can change some settings. When the view is dismissed, I'd like to update the title/text of the UIButton to reflect the new state. I'm calling:

[myButton setTitle: @"myTitle" forState: UIControlStateNormal];
[myButton setTitle: @"myTitle" forState: UIControlStateApplication];
[myButton setTitle: @"myTitle" forState: UIControlStateHighlighted];
[myButton setTitle: @"myTitle" forState: UIControlStateReserved];
[myButton setTitle: @"myTitle" forState: UIControlStateSelected];
[myButton setTitle: @"myTitle" forState: UIControlStateDisabled];

But it never seems to change from the original text/title as specified in IB.

+5  A: 

Do you have the button specified as an IBOutlet in your view controller class, and is it connected properly as an outlet in Interface Builder (ctrl drag from new referencing outlet to file owner and select your UIButton object)? That's usually the problem I have when I see these symptoms.

Ken Pespisa
Bingo, that was it, thanks. I really wish Objective-C would just throw a NullPointerException in cases like this, instead of silently pretending that it's OK to send a message to a nil object. This bites me almost daily... ugh!
Caffeine Coma
ObjC doesn't 'pretend' its OK to send a message to nil, because it *is* OK to send messages to nil...
Jasarien
The issue here is not a nil pointer. The issue is that IB has setup a UIButton instance that isn't being referenced properly in the code (via IBOutlet), so it can never be manipulated programmatically.
LucasTizma