简体   繁体   中英

IBoutlets nil in swift when using storyboards

In one of my ViewController s, 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 IBOutlet s in that viewController is nil (notice that other viewController s 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM