Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewDidLayoutSubviews infinite loop with iOS 8

i have a Universal iOS project that run perfectly with Xcode 5 (iOS 6 & iOS 7). I use different storyboard for iPad & iPhone.

When i run it with Xcode 6 GM, it works perfectly with iPhone but doesnt work with iPad. I debugged i found that there is problem with viewDidLayoutSubviews in UISplitViewController. For example:

- (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; NSLog(@"run"); // some config with frame of child controllers }

It runs continuously and didnt stop.

Anyone has the same problem? Please help :(

Thank you!

like image 748
Nguyễn Lương Bằng Avatar asked Sep 17 '14 03:09

Nguyễn Lương Bằng


3 Answers

The code you have inside the viewDidLayoutSubviews override for the child controllers is itself modifying the subviews of the view, and so is triggering viewDidLayoutSubviews to be called again, and again, and again.

To prevent this, try adding a BOOL property to your UISplitViewController to control the execution of the child controllers layout code.

@interface UISplitViewController()
...
@property (nonatomic) BOOL subViewLayoutCalled;
...
@end

Then in your viewDidLayoutSubviews...

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    NSLog(@"run");
    if (!self.subViewLayoutCalled) {
        self.subViewLayoutCalled = YES;
        // some config with frame of child controllers
    }
}

It's worth a go.

I had the same problem recently.

like image 135
Chris Butcher Avatar answered Oct 10 '22 06:10

Chris Butcher


What I had seen it's every time you change the layout of your elements in your view it will call the following methods:

viewWillLayoutSubviews;
viewDidLayoutSubviews;

if you change something into the last, it will call it again;

like image 31
orafaelreis Avatar answered Oct 10 '22 05:10

orafaelreis


I had the same problem - used it to resize the master/detail in UISplitViewCtrl.

To change the size master/detail try this new parameters in ios8, in for example viewDidLoad:

self.minimumPrimaryColumnWidth = 500;
self.maximumPrimaryColumnWidth = 500;
self.preferredPrimaryColumnWidthFraction = 1;
like image 20
developer9911 Avatar answered Oct 10 '22 05:10

developer9911