objective-cuilabeliboutletxcode4.6awakefromnib

awakeFromNib can't get value from UILabel and can't disable UIButton


I have two buttons in single-view app main storyboard and would like to disable one of them as well as get value from the UILabel using awakeFromNib method. As far as I concern all relationships and GUI items must be initialized and values must be assigned before calling the awake method. Unfortunately I am not able to do get the value and disable button by applying

- (void)awakeFromNib {
     decreaseButton.enabled = NO;
     decreaseButton.alpha = 0.2;
     [polygon initWithNumberOfSides:numberOfSidesLabel.text.integerValue     
               minimumNumberOfSides:3
               maximumNumberOfSides:12]; 
}

to the class I have made. I have established the connection between the UILabel and

IBOutlet UILabel *numberOfSidesLabel;

in my created class file. Can somebody see the mistake or shall I provide more info on the problem?


Solution

  • First, you must call [super awakeFromNib]; when you override this method.

    Second, standard practice is to use viewDidLoad. Try that instead.