36

Wondering if anyone else has encountered this issue recently...

For one of my view controllers , only on iOS 8, after calling presentViewController:animated:completion:, the presented view controller has self.presentingController as nil. It is fine on iOS7, and also does not happen on another view controller.

The documentation says that it should be set, as long as the presented view controller was presented modally. Given it works in iOS 7, could this be an iOS 8 bug?

I've been able to get around it using a view container containment approach, but it would be good if someone has seen this before and knows the root cause that triggered this behaviour.

thanks

Ken Ko
  • 1,517
  • 2
  • 15
  • 21
  • Where did you log this. It's not null in viewWillAppear, or viewDidAppear, but is in viewDidLoad. I don't remember if that's different from iOS 7. – rdelmar Sep 28 '14 at 04:46
  • 1
    The presented controller is a 3rd party one which i don't have access to step through (FBFriendPickerViewController). I'm seeing it as nil when i hit a breakpoint on the line after the call to `presentViewController:animated:completion:` from the presenting controller's code breakpoint – Ken Ko Sep 28 '14 at 08:27

1 Answers1

54

Had a similar issue with iOS 8, where presentingController is nil when checking the value in viewDidLoad.

When viewDidLoad is called, there is no guarantee that the view controller hierarchy is loaded in the navigation tree. Moving the logic to a later stage (for example: viewWillAppear) should resolve that issue as presentingController should be loaded by then.

Feras Arabiat
  • 826
  • 6
  • 11
  • 2
    This helped me out. I needed a pointer to the `presentingViewController` in a function. I created a property, access, and store a pointer to `presentingViewController` in `viewDidAppear` for use later. – Pouria Almassi Jun 28 '16 at 06:01
  • This saved me so much hair-pulling - thanks! My assumption is that this value would be set at viewdidload – Nostradamus Aug 30 '21 at 19:57