Search code examples
iosxcodeios7xcode5

'NSInvalidArgumentException', reason: 'Sheet can not be presented because the view is not in a window


After upgrading Xcode from Version 4 to 5 and therefore from iOS 6 to iOS 7 i get the following error:

'NSInvalidArgumentException', reason: 'Sheet can not be presented because the view is not in a window

in this line:

[actionSheet showInView:self.view];

Solution

  • I literally just had this exact same problem and unfortunately I'm still not sure what the root cause of the problem is. However, you'll find my current solution below. If I make any progress on root causing the issue I'll let you know.

    UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
    if ([window.subviews containsObject:self.view]) {
        [emailSheet showInView:self.view];
    } else {
        [emailSheet showInView:window];
    }