iOS 9.2 unable to change title of a UIButton programmatically once it is set in storyboard

262 Views Asked by At

I'm running into a weird issue where I'm unable to change the title of a UIButton defined in storyboard. The button is embedded into a stack view within a scroll view. The button's callback is executed correctly and triggers breakpoint, but the title can't be changed.

I tried different states, besides normal but it does not seem to have any effect:

 [self.button setTitle:[NSString stringWithFormat:@"test %i",1] forState:UIControlStateNormal];
[self.button setNeedsLayout];
[self.button layoutIfNeeded];

enter image description here

1

There are 1 best solutions below

1
On

:( Turns out I copied the button from one view controller to another (same view controller class in the identity inspector), and all the outlets were appearing as correct. However, it appears they are bugged in such case. Manually deleting every button callback and IBOutlet and reconnecting solved the issue.

To clarify: To see if you are having the same issue, set a breakpoint and check if the button reference is nil. If it is nil and you are seeing that the outlet is set in storyboard, delete the outlet connection and reconnect.