iosxcodeuiviewsubviewsuperview

Buttons not returned by subviews in Compact:Regular


I am writing an application for iOS. I have 3 buttons (of a custom UIButton subclass) in my view, each are added graphically through IB. I was running into a bug that I realized was coming from the fact that only one of the buttons' superview is self.view (where self is the ViewController). The other buttons belong to these things:

<_UILayoutGuide: 0x7f92d3d75d50; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7f92d3d76070>>

I have absolutely no idea why they are being added to this subview instead of being direct subviews of self.view. While I could deal with the fact that they are not direct subviews with some extra code, I would like to know first why they aren't direct subviews.

EDIT:

I created an IBAction that gives the superview of the button when I click it, and when I click it, I get the view. However, when I try to look for the buttons in self.view.subviews, they're not there.

EDIT 2:

I have figured out that when the ViewController is in Any:Any, the subviews are returned just fine by self.view.subviews. If I switch it to Compact:Regular (which is what I need), all bets are off.


Solution

  • You need to get the subviews from self.view in viewDidLayoutSubviews() function, which is called to notify the view controller that its view has just laid out its subviews.