Reputation: 24017
I have a view that gets presented when the user flips the phone to Landscape. It's presented by a UIViewController that's on top of a Navigation Control stack by using PresentViewController().
It works fine until the user pulls-down the Notification Center by dragging down from the top of the phone's screen, then the app instantly crashes with a MonoTouchException and the message:
"Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Application tried to present modally an active controller"
This crash does not occur when pulling down the Notification Center in any other view, but all of the other views are on the Navigation Controller's stack and not presented modally.
Upvotes: 2
Views: 1393
Reputation: 24017
Figured it out with a bit more debugging:
I was subscribing to UIDeviceOrientationDidChangeNotification to find out when the phone was rotated and calling a "DeviceRotated()" method.
It turns out that when you pull down the Notification Center, this notification gets fired again even if the phone hasn't physically changed rotation. My code wasn't expecting this, so it tried to present the same Landscape View again while it was already being displayed, and the exception was thrown.
I added && (this.PresentedViewController == null || this.PresentedViewController == this)
to the if-then
that tests for the right circumstances to present the landscape view and the crash went away.
Upvotes: 2