Accessing UIViewcontroller.traitCollection compile

2019-08-24 03:22发布

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

2条回答
劳资没心,怎么记你
2楼-- · 2019-08-24 03:54

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.

查看更多
登录 后发表回答