Eli Waxman
Eli Waxman

Reputation: 2897

IBoutlets nil in swift when using storyboards

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.

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

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

Edit: 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.

Upvotes: 0

Views: 898

Answers (1)

matt
matt

Reputation: 534885

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:

  • 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.

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.

Upvotes: 2

Related Questions