当使用storyboards时,IBoutlets在swift中为零 [英] IBoutlets nil in swift when using storyboards

查看:196
本文介绍了当使用storyboards时,IBoutlets在swift中为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 ViewController 之一,当我到 viewWillAppear ,我的 IBOutlets nil ,我尝试看看@ matt`s解决方案,但它适用于nibs不在故事板。

In one of my ViewControllers, when I get to viewWillAppear, all my IBOutlets are nil, I tried looking at @matt`s solution but it works for nibs not in Storyboards.

这是我在iOS 7的设备上运行应用程序时只是一个问题。它不会发生在其他设备上。

This is only a problem when I run the app on devices that are on iOS 7. It doesn't happen on other devices.

任何人都知道为什么所有 IBOutlet viewController 是nil(注意其他 viewController s可以正常工作。)

Does anyone know why all my IBOutlets in that viewController is nil (notice that other viewControllers works fine.)

编辑
尝试创建一个新的 ViewController 在故事板中,有一些标签和一个新的TestViewController.swift文件,并连接它们,仍然获得nil值,请理解,项目的其余部分工作很好。

Tried creating a new ViewController in the storyboard, with some labels, and a new TestViewController.swift file, and connecting them, still getting nil values, please understand that the rest of the project works just fine.

推荐答案

事实上,你只在iOS 7上有问题显然是一个主要线索。我看了你发布的测试项目,我的建议是,问题可能是两个方面:

The fact that you're having problems only on iOS 7 is clearly a major clue. I looked at the test project you posted, and my suggestion is that the problem is probably two-fold:


  • 在你的故事板中使用大小类。但是在iOS 7中没有大小类,因此不能向后兼容。

  • You've used size classes in your storyboard. But in iOS 7 there are no size classes so that's not backwards-compatible.

有些视图,仅安装一种尺寸类型 - 紧凑的高度。因此,在具有常规高度的设备/定向上,这些视图将丢失,并且到它们的插座将是零。

Some of your views, perhaps the views that you're having trouble with, are installed for one size class only — compact height. So on a device / orientation with regular height, those views will be missing and the outlets to them will be nil. Those are what I call conditional views.

我的猜测是你'只有这一个视图控制器的这个问题是,这可能是唯一的视图控制器在您的故事板中的视图包含任何条件视图。条件视图,如它们所依赖的大小类,不能向后兼容到iOS 7;所以也许整个事情只是放弃在笔尖装载时间,这就是为什么你根本没有得到任何意见。

My guess is that the reason you're having this problem only for this one view controller is that this is probably the only view controller in your storyboard whose view contains any conditional views. Conditional views, like the size classes on which they depend, are not backwards-compatible to iOS 7; so perhaps the whole thing just gives up at nib-loading time, and that's why you don't get any views at all.

这篇关于当使用storyboards时,IBoutlets在swift中为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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