0

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

rswayz
  • 892
  • 2
  • 7
  • 20
  • Please add the stack trace for the infinite loop. From this you are sharing, it looks like you are somehow triggering a call `[self.view layoutSubviews]` which will in turn eventually call `[self viewDidLayoutSubviews]` adn so on. If I had to guess, the problem lies in the `.......` part of your code. Please share that! – pevasquez Oct 31 '15 at 22:08
  • 1
    Are you possibly reloading data inside the viewDidLayoutSubviews? – Yan Nov 01 '15 at 04:00

1 Answers1

2

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.

rob mayoff
  • 342,380
  • 53
  • 730
  • 766
  • Good tip, thanks. That, and adjusting which view the UIImageView was being added to (PFLoginViewController.view vice PFLoginViewController.loginView) did the trick! – rswayz Nov 01 '15 at 20:01