ios - 在 View Controller 出现之前,Objective C 中的 IBOutlet 为零

标签 ios objective-c viewcontroller iboutlet presentation

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/

相关文章:

ios - 分发内部业务 IOS 应用程序

ios - Swift - UIButton 没有固定在屏幕底部

ios - ios mvc模式中的http请求

objective-c - UIActivityViewController 如何将字符串转换为打印

ios - 持久的 iOS 页脚 UIView

ios - 从 appDelegate 启动导航 Controller

ios - init 不调用自定义类 swift

ios - 将二进制文件上传到 iTunes Connect 时无法更改预渲染图标标志

swift - 在 swift 中切换 View Controller 时内存使用量增加

ios - 如果 ViewController 包含 TableView 作为根目录,如何将它添加到导航 Controller ?