PFLoginViewController infinite loop from viewDidLayoutSubviews?

319 Views Asked by At

Has anyone run into an issue in iOS 9 with PFLoginViewController (from the ParseUI framework)?

In iOS 8, per the Parse documentation, I set up the custom fields to the LoginViewController in viewDidLayoutSubviews, however, in iOS 9, it enters into an infinite loop and will not exit out of the viewDidLayoutSubviews method.

(void)viewDidLayoutSubviews {
    NSLog(@"didLayoutSubviews");
    [super viewDidLayoutSubviews];

    float width = self.view.frame.size.width;
    float height = self.view.frame.size.height;
    ......
    [self.logInView addSubview:backgroundImage]; // <- the line here causes an infinite loop

}

Update: I've narrowed it down to the culprit: addSubview is the line causing the infinite loop. But again, it only causes it in iOS9...throughts?

Update 2: For all ParseUI users, the answer (thanks to the thoughts of the respondents below) is that although it worked in iOS 8 with that Parse, you can no longer add a background image to PFLoginViewController in the viewDidLayoutSubviews, as was documented previously. Also the same adding the background to the PFLoginViewController.loginView at viewDidLoad does not work.

Solution: Move adding any subiews to the viewDidLoad method and do not add subviews to the PFLoginViewController.loginView; instead add the subview directly to the PFLoginViewController.view

1

There are 1 best solutions below

1
rob mayoff On

Whenever a view's subviews array changes, it flags itself as needing layout. Since you're adding a subview immediately after layout has finished, you are triggering another layout pass. Why would you want to add a subview on every layout pass anyway?

You should not add a subview in viewDidLayoutSubviews. You should add it in viewDidLoad, and use either constraints or autoresizing to make sure the subview's frame is set correctly by the layout pass.