ios - 在呈现视图控制器之前,目标 C 中的 IBOutlet 为零
问题描述
UIStoryboard *gamePlaySB = [UIStoryboard storyboardWithName:STORYBOARD_GAME_PLAY bundle:nil];
CustomAlertViewController *customAlertVC = [gamePlaySB instantiateViewControllerWithIdentifier:CUSTOM_ALERT_VIEW_CONTROLLER];
我已经初始化了viewcontroller
如上所示,但是当尝试IBOutlet
从初始化的标签中访问标签viewcontroller
并设置其文本时,标签为 nil。
所以,我必须将值传递给一个变量,然后在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。米卡回答,这是不可取的。
推荐阅读
- python - Sqlalchemy - 如何在 self 不可用的上下文中定义 scopefunc?
- mysql - 关系问题 (PHPMyAdmin) - 添加键,在关系视图中不可见
- azure - 如何在 Azure 数据工厂管道中直接转换 JSON 数据
- python - 如何创建一个函数来查找字典中的所有回文(包括 i 和 a)?
- firebase - 更新 Firestore 中 Array 的 Map 数据 - Flutter
- go - 如何解码使用 goavro.OCFWriter 编码的 Avro 消息?
- python - 在与列表混合的嵌套字典中查找键
- python - 函数不改变数组
- html - 从R中的网页解析“表单操作”属性
- c++ - "No match for operator>" when using priority queue in C++