IBoutlets nil in swift when using storyboards

后端 未结 1 978
庸人自扰
庸人自扰 2021-01-29 05:45

In one of my ViewControllers, when I get to viewWillAppear, all my IBOutlets are nil, I tried looking at @matt`s solution but

相关标签:
1条回答
  • 2021-01-29 06:08

    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.

    0 讨论(0)
提交回复
热议问题