storyboard instantiateViewControllerWithIdentifier未设置IBOutlets [英] storyboard instantiateViewControllerWithIdentifier not setting IBOutlets

查看:189
本文介绍了storyboard instantiateViewControllerWithIdentifier未设置IBOutlets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用storyboard instantiateViewControllerWithIdentifier:而且我注意到我已连线的所有 IBOutlets 仍然零。但是, IBActions 我已经连线工作了。视图和控制器是链接的(即controller.view不是nil),如果我显示视图,它会显示我期待的内容。

I am using storyboard instantiateViewControllerWithIdentifier: and I'm noticing that all the IBOutlets I have wired up are still nil. However, the IBActions I have wired up work. The view and controller are linked (i.e controller.view is not nil), and if I show the view it displays what I am expecting.

我缺少什么?

这是我的设置:


  1. 我是在我的故事板中定义了一个View Controller。我给它一个标识符,它与我在调用 instantiateViewControllerWithIdentifier时使用的标识符相同:

  2. 我已经设置了视图的所有者单击View Controller(位于First Responder下)并在Identity Inspector下将Custom Class设置为与我要将视图连接到的类相同的名称。

  3. 然后我打开up助手编辑器和控件拖动UI元素以创建 IBOutlets IBActions

  1. I've got a View Controller defined in my storyboard. I have given it an identifier which is the same identifier I use when invoking instantiateViewControllerWithIdentifier:
  2. I've set up the view's owner by clicking on the View Controller (just under First Responder) and under the Identity Inspector set the Custom Class to be the same name as the class I want to wire the view to.
  3. Then I open up Assistant editor, and control dragged the UI elements to create the IBOutlets and IBActions.


推荐答案

视图似乎只有在首先访问后才能正确初始化。调用时问题就消失了

The view seems to be initialized properly only after it is accessed first. The problem goes away when calling

[self presentViewController:vc animated:NO completion:nil];

或更简单

[vc view];

这篇关于storyboard instantiateViewControllerWithIdentifier未设置IBOutlets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆