首页 > 解决方案 > 在呈现视图控制器之前,目标 C 中的 IBOutlet 为零

问题描述

UIStoryboard *gamePlaySB = [UIStoryboard storyboardWithName:STORYBOARD_GAME_PLAY bundle:nil];
CustomAlertViewController *customAlertVC = [gamePlaySB instantiateViewControllerWithIdentifier:CUSTOM_ALERT_VIEW_CONTROLLER];

我已经初始化了viewcontroller如上所示,但是当尝试IBOutlet从初始化的标签中访问标签viewcontroller并设置其文本时,标签为 nil。

所以,我必须将值传递给一个变量,然后在viewDidLoad设置标题中使用它。有没有其他简单的方法可以做到这一点?

标签: iosobjective-cviewcontrolleriboutletpresentation

解决方案


CustomAlertViewController *customAlertVC = [gamePlaySB instantiateViewControllerWithIdentifier:CUSTOM_ALERT_VIEW_CONTROLLER];
__unused UIView* view = customAlertVC.view; // this will load everything and call viewDidLoad
customAlertVC.property.text = @"blahblah";

这是如果真的想从外面设置它。但根据@D。米卡回答,这是不可取的。


推荐阅读