Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autolayout and subviews

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

like image 598
Kevin Tarr Avatar asked Aug 25 '13 13:08

Kevin Tarr


People also ask

What is Autolayout?

Auto Layout defines your user interface using a series of constraints. Constraints typically represent a relationship between two views. Auto Layout then calculates the size and location of each view based on these constraints. This produces layouts that dynamically respond to both internal and external changes.

What is Autolayout aspect ratio?

If you select Aspect Ratio for multiple items, Auto Layout chooses the width of one of the items for the numerator and the height of another item for the denominator. To change the initial aspect ratio, edit the Multiplier field of the Attributes inspector for the constraint.

When should I use layoutSubviews?

layoutSubviews() The system calls this method whenever it needs to recalculate the frames of views, so you should override it when you want to set frames and specify positioning and sizing. However, you should never call this explicitly when your view hierarchy requires a layout refresh.

When can I call super layoutSubviews?

You always have to call [super layoutSubviews] last, if the intrinsic content size of a view will be changed. If you change the title of the button, the intrinsic content size of the UIButton will be changed, therefore the last call.


1 Answers

Add:

[self.view layoutIfNeeded]; 

to the end of this method

- (void)viewDidLayoutSubviews 

inside your BannerViewController

like image 145
junjie Avatar answered Sep 23 '22 02:09

junjie