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];
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]; }
I got the same problem. In my code, the reason obviously was that I wanted to show an action sheet in viewWillAppear:
.
After moving the code to viewDidAppear:
, the error was gone.
I don't know what is the root cause of the problem is, but I found a solution which is working for me. In place of self.view
, place this line:
[[[[UIApplication sharedApplication] keyWindow] subviews] lastObject]
for example:
[actionSheet showInView:[[[[UIApplication sharedApplication] keyWindow] subviews] lastObject]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With