Eugene Zhenya Gordin Eugene Zhenya Gordin - 3 months ago 27
iOS Question

viewDidLayoutSubviews is getting called infinitely after switching to xcode 6

My perfectly working iOS app stopped working properly after switching to xcode 6. I found out that in one of my view controllers viewDidLayoutSubviews method is getting called infinitely until the memory level reaches to some point when the app is crashing due to that.

Does anyone have any ideas why this might be happening? I also noticed that some of my views started to look weird after switching to xcode 6, but I fixed those issues in storyboard.

Any kind of help is highly appreciated!

EDIT 1.

-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];

if (self.showsPlayerControls == NO) {
self.playerControlsView.hidden = YES;
CGRect graphFrame = self.view.bounds;

graphFrame.size.height = graphFrame.size.height - 20.0f;
graphFrame.origin.y = 20.0f;

self.graphView.frame = graphFrame;
}

[self.graphView reloadData];
}


EDIT 2.

My fix is the following, basically move my code to viewWillAppear.

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

if (self.showsPlayerControls == NO) {
self.playerControlsView.hidden = YES;
CGRect graphFrame = self.view.bounds;

graphFrame.size.height = graphFrame.size.height - 20.0f;
graphFrame.origin.y = 20.0f;

self.graphView.frame = graphFrame;
}

[self.graphView reloadData];
}


Is this a good equivalent of what I want to achieve ?

Answer
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (self.showsPlayerControls == NO) {
        self.playerControlsView.hidden = YES;
        CGRect graphFrame = self.view.bounds;

        graphFrame.size.height = graphFrame.size.height - 20.0f;
        graphFrame.origin.y = 20.0f;

        self.graphView.frame = graphFrame;
    }

    [self.graphView reloadData];
}