0

I'm using ECSlidingViewController with a left & right side menus.

Trying to get iAds to display at the bottom of the whole app. My StoryBoard entry point is a ViewController that is a ECSlidingViewController subclass.

The storyboard is set for AutoLayout along with all my other code.

When I add self.canDisplayBannerAds = YES; into viewWillAppear the build fails with:

    View hierarchy unprepared for constraint.
    Constraint: <NSAutoresizingMaskLayoutConstraint:0xb2a9030 h=--- v=--- UIView:0xa499b70.midX == UIView:0xa4a95f0.midX>
    Container hierarchy: 
<UIView: 0xa4a95f0; frame = (0 0; 768 1024); layer = <CALayer: 0xa4a84d0>>
    View not found in container hierarchy: <UIView: 0xa499b70; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0xa499380>>
    That view's superview: <UIWindow: 0xb263e30; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0xb264f30>; layer = <UIWindowLayer: 0xb264080>>
2014-01-06 20:22:15.772 AppTest[10851:a0b] View hierarchy unprepared for constraint.
    Constraint: <NSAutoresizingMaskLayoutConstraint:0xb2a9180 h=--- v=--- UIView:0xa499b70.width == UIView:0xa4a95f0.width>
    Container hierarchy: 
<UIView: 0xa4a95f0; frame = (0 0; 768 1024); layer = <CALayer: 0xa4a84d0>>
    View not found in container hierarchy: <UIView: 0xa499b70; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0xa499380>>
    That view's superview: <UIWindow: 0xb263e30; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0xb264f30>; layer = <UIWindowLayer: 0xb264080>>
2014-01-06 20:22:15.772 AppTest[10851:a0b] View hierarchy unprepared for constraint.
    Constraint: <NSAutoresizingMaskLayoutConstraint:0xb2a92b0 h=--- v=--- UIView:0xa499b70.midY == UIView:0xa4a95f0.midY>
    Container hierarchy: 
<UIView: 0xa4a95f0; frame = (0 0; 768 1024); layer = <CALayer: 0xa4a84d0>>
    View not found in container hierarchy: <UIView: 0xa499b70; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0xa499380>>
    That view's superview: <UIWindow: 0xb263e30; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0xb264f30>; layer = <UIWindowLayer: 0xb264080>>
2014-01-06 20:22:15.815 AppTest[10851:a0b] View hierarchy unprepared for constraint.
    Constraint: <NSAutoresizingMaskLayoutConstraint:0xb2a92e0 h=--- v=--- UIView:0xa499b70.height == UIView:0xa4a95f0.height>
    Container hierarchy: 
<UIView: 0xa4a95f0; frame = (0 0; 768 1024); layer = <CALayer: 0xa4a84d0>>
    View not found in container hierarchy: <UIView: 0xa499b70; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0xa499380>>
    That view's superview: <UIWindow: 0xb263e30; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0xb264f30>; layer = <UIWindowLayer: 0xb264080>>
2014-01-06 20:22:15.815 AppTest[10851:a0b] View hierarchy unprepared for constraint.
    Constraint: <NSAutoresizingMaskLayoutConstraint:0xb2a9030 h=--- v=--- UIView:0xa499b70.midX == UIView:0xa4a95f0.midX>
    Container hierarchy: 
<UIView: 0xa4a95f0; frame = (0 0; 768 1024); layer = <CALayer: 0xa4a84d0>>
    View not found in container hierarchy: <UIView: 0xa499b70; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0xa499380>>
    That view's superview: <UIWindow: 0xb263e30; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0xb264f30>; layer = <UIWindowLayer: 0xb264080>>
2014-01-06 20:22:15.838 AppTest[10851:a0b] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view.  Does the constraint reference something from outside the subtree of the view?  That's illegal. constraint:<NSAutoresizingMaskLayoutConstraint:0xb2a9030 h=--- v=--- UIView:0xa499b70.midX == UIView:0xa4a95f0.midX> view:<UIView: 0xa4a95f0; frame = (0 0; 768 1024); layer = <CALayer: 0xa4a84d0>>'

Looks like I need to add a constraint somewhere as the height will alter when iAds are displayed.

JMWhittaker
  • 3,633
  • 3
  • 23
  • 30

2 Answers2

1

First, set canDisplayBannerAds before the view is displayed (i.e. when the view is loaded).

Second, update the view so that it doesn't have automatically converted auto-resizing constraints (see translatesAutoresizingMaskIntoConstraints).

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Setting 'translatesAutoresizingMaskIntoConstraints = NO' on the ECSlidingViewController subclass causes the sidepanels to not display correctly & it's impossible to close them again. – JMWhittaker Jan 07 '14 at 09:15
  • You would need to set appropriate frames / constraints then. I would be very tempted not to use `canDisplayBannerAds` and instead just add a banner yourself to the main view (so ads won't be shown on the side panels)... – Wain Jan 07 '14 at 10:57
  • Wain, yes that's what I currently have. Was a little concerned about app store review but going to submit it anyway. I'll keep trying out different solutions. – JMWhittaker Jan 07 '14 at 20:55
  • Why concerned? The app surely doesn't spend a lot of time in the side panels? – Wain Jan 07 '14 at 22:15
0

I think the issue you're having is that you're trying to resize ECSlidingViewController's subviews. You should resize ECSlidingViewController's view instead.

I would create a container view controller and make that the entry point. The child views would be the iAd view and ECSlidingViewController's view.

Michael Enriquez
  • 2,520
  • 21
  • 13
  • Hi Mike thanks a lot for this tool, I have a question http://stackoverflow.com/questions/22308531/how-to-go-back-to-current-view-controller?noredirect=1#comment33898011_22308531 can you please help? –  Mar 10 '14 at 18:59