問題描述
awakeFromNib 無法從 UILabel 獲取值,也無法禁用 UIButton (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?
‑‑‑‑‑
參考解法
方法 1:
First, you must call [super awakeFromNib];
when you override this method.
Second, standard practice is to use viewDidLoad
. Try that instead.