I can show the actionSheet in iOS 7 but cannot show in iOS 8 environment. Is there any way to trace?
UIActionSheet *_actionSheet = [[UIActionSheet alloc] initWithTitle:@"Account"
delegate:self
cancelButtonTitle:@"Close"
destructiveButtonTitle:@"Log Out"
otherButtonTitles:@"View Account", nil];
[_actionSheet showInView:appDel.window];
UIActionSheet is deprecated in iOS 8.
To create and manage action sheets in iOS 8 you should use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.
Refer this example.
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Info"
message:@"You are using UIAlertController"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
It's clearly a regression in iOS 8. I have filed a rdar, please do so, too.
In the meantime, you can fix it with a category or a subclass where you check whether the view is a window, and if so, then grab the rootViewController's view on that window and use it instead. It'll work that way.
I had issues with action sheets when iOS 8 came out. It is likely an issue with the view you are presenting in. Can you show it in an actual view rather than the window? I'd experiment there first, and as a worst case, wrap the show method up in something specific for iOS 7 and 8. I started using PSTAlertController to manage my alerts and action sheets. It supports UIAlertView, UIActionSheet, and UIAlertController. It will sort out which one to use, as well as give you access to block actions for your buttons while still supporting iOS 7 and 8. Worth a look.
If anyone else sees this issue, the problem is actually caused by iOS 8 and 9 displaying your action sheet behind the onscreen keyboard, so you can't actually see it. You just see the rest of the screen going darker. Genius.
The simple solution is to add one line of code before displaying your UIActionSheet
:
[self.view endEditing:true];
This dismisses the onscreen keyboard, making your beautiful action sheet visible again.