Autolayout and subviews
Asked Answered
C

1

28

I am using the iAd suite with storyboards from Apple, as per this link... Apple iAd Storyboard documentation

It all works fine until I turn autolayout on. It builds fine but crashes on running. The output I get is:

2013-08-24 12:06:36.138 TabbedBanner[7272:c07] * Assertion failure in -[UIView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2380.17/UIView.m:5781 2013-08-24 12:06:36.139 TabbedBanner[7272:c07] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after sending -viewDidLayoutSubviews to the view controller. BannerViewController's implementation needs to send -layoutSubviews to the view to invoke auto layout.' *** First throw call stack: (0x1e27012 0x110ee7e 0x1e26e78 0xba4665 0xa347a 0x11226b0 0x1358fc0 0x134d33c 0x1358eaf 0x1422bd 0x8ab56 0x8966f 0x89589 0x887e4 0x883ef 0x65c9d 0x5098b 0x5194b 0x62cb5 0x63beb 0x55698 0x1700df9 0x1700ad0 0x1d9cbf5 0x1d9c962 0x1dcdbb6 0x1dccf44 0x1dcce1b 0x5117a 0x52ffc 0x2a0d 0x2935) libc++abi.dylib: terminate called throwing an exception (lldb)

I know it is something to do with the subviews in storyboard but I dont know how to correct this error. I am pretty new to iOS and trying to teach myself so any help is appreciated. Many Thanks

Cerebritis answered 25/8, 2013 at 13:56 Comment(0)
S
88

Add:

[self.view layoutIfNeeded];

to the end of this method

- (void)viewDidLayoutSubviews

inside your BannerViewController

Streaky answered 29/8, 2013 at 11:41 Comment(5)
Consider using [self.view layoutIfNeeded] instead of layoutSubviews (which, according to the docs, shouldn't be called directly). This should still solve the problem of needing to re-layout.Madelina
What is the reason behind needing to call layout if needed? Is it because the subviews aren't setup until viewDidLayoutSubviews is called?Reneareneau
It happens to me only on iOS 7 when using Xcode 6 to design app for iOS 8 and 7, and overriding viewDidLayoutSubviews. I know some things changed in the order of the view lifecycle on iOS 8 but this is just happening to me when using iOS 8 SDK or iOS 7 app... iOS 7 is not able to layout views properly at the end of the first "viewDidLayoutSubviews" call and you have to re-layout them after modifying things in the overrided methodEckblad
I wonder if putting the call to [super viewDidLayoutSubviews] at the end of the method would do the trick tooEckblad
this cause infinite recursion iOS 9.2Hangover

© 2022 - 2024 — McMap. All rights reserved.