2

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.

ericmarkmartin
  • 717
  • 1
  • 8
  • 19
  • The frame is zero, so make it bigger in storyboard. – gabbler Nov 12 '14 at 01:38
  • Make what bigger, the button? They're each 191x71 – ericmarkmartin Nov 12 '14 at 01:43
  • The frame,you can try to move the button to the center of the view and try again, it might be misplaced. – gabbler Nov 12 '14 at 01:47
  • What frame? Two of the button's x values are -2, could that be it? It was necessary because of some aesthetics with the border – ericmarkmartin Nov 12 '14 at 01:47
  • How are you determining that the button's superview is the UILayoutGuide? – rdelmar Nov 12 '14 at 01:54
  • I have this method in the UIViewController: @IBAction func buttonTapped(sender : KeyRecognizeButton) { println("Superview:\(sender.superview)") println("Super-superview:\(sender.superview?.superview)") } which prints layout thingy and then view for two out of the three buttons. – ericmarkmartin Nov 12 '14 at 01:57
  • I would delete the 2 bad buttons, and add them again to your view in the storyboard. I don't know how you could add them to a layout guide -- I tried to do that, but it wouldn't let me. – rdelmar Nov 12 '14 at 02:22
  • To clarify, I'm trying to not add them to the layout guide. I deleted the bad buttons and re-added them, still no dice. – ericmarkmartin Nov 12 '14 at 02:42
  • Really odd thing, In the storyboard ViewController scene, they are both listed as being under the view. – ericmarkmartin Nov 12 '14 at 02:44

1 Answers1

0

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.

Cristina
  • 16
  • 2