UIStoryboard *gamePlaySB = [UIStoryboard storyboardWithName:STORYBOARD_GAME_PLAY bundle:nil];
CustomAlertViewController *customAlertVC = [gamePlaySB instantiateViewControllerWithIdentifier:CUSTOM_ALERT_VIEW_CONTROLLER];
我已经初始化了 viewcontroller
如上所示,但是当尝试从初始化的 viewcontroller
访问 IBOutlet
标签并设置其文本时,标签为零。
因此,我必须将值传递给变量,然后在 viewDidLoad
中使用该值来设置标题。还有其他简单的方法吗?
最佳答案
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。 Mika回答,这是不可取的。
关于ios - 在 View Controller 出现之前,Objective C 中的 IBOutlet 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54072119/