Accessing UIViewcontroller.traitCollection compiles but crashes my app

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:57:14

问题


My storyboard is build in xcode6 and is using the new constraint based layouts. My app runs in two configurations, wRegular hRegular and wCompact hAny. Any time I try to access the traitCollection in code I get the following error:

[MYUIControllerName traitCollection]: unrecognized selector sent to instance.

I have also tried implementing the following function, but it never gets called.

-(void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

回答1:


I don't think it's exactly right that size classes don't work < iOS 8. https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/DeployingSizeClassesonEarlieriOSVersions.html#//apple_ref/doc/uid/TP40014436-CH13-SW1




回答2:


I got the same issue. The answer is use trait collection only in viewWillAppear and willTransitionToTraitCollection. Theses are the only method when you can be sure they are set and correctly set. In iOS8 it can not crash but your trait collection will be unspecified.



来源:https://stackoverflow.com/questions/25923523/accessing-uiviewcontroller-traitcollection-compiles-but-crashes-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!