UIActionSheet not showing in iOS 8
Asked Answered
P

5

4

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];
Polychromy answered 26/9, 2014 at 14:27 Comment(3)
It's because UIActionSheets don't exist anymore in iOS8 they have been deprecated in favor of UIAlertController Have a read of developer.apple.com/Library/ios/documentation/UIKit/Reference/…Bertie
@Bertie "deprecated" does not mean "eliminated" but rather "please avoid". It should still work thoughEchoism
In my iPhone app, no, it didn't work anymore. With iOS 9, my UIActionSheet merely darkened the entire screen now, and no popup menu would appear. Details of my fix here: #32824699 (Sigh...)Rutger
C
3

UIActionSheet is deprecated in iOS 8.

enter image description here

To create and manage action sheets in iOS 8 you should use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.

Refer this example.

Circassia answered 26/9, 2014 at 14:45 Comment(1)
I refer to this page as well but I am getting " You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation." I refer to other page but I'm stucked at the button part. #24225416Polychromy
C
1
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];
Captivity answered 9/12, 2015 at 6:23 Comment(0)
F
0

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.

Finnigan answered 6/12, 2014 at 14:7 Comment(0)
M
0

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.

Manner answered 6/12, 2014 at 15:0 Comment(0)
R
0

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.

Rutger answered 11/2, 2016 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.