UIAlertView and UIActionSheet not displaying prope

2019-03-29 22:03发布

问题:

UIAlertView and UIActionSheet not displaying properly in iOS 8, its hiding the view controller, also In alert view title is not displaying. I am running the app from Xcode 5.1.1.

回答1:

Did you added any category for ViewController in your application. like below shown

@implementation UIViewController (CustomeAction)
- (void)setTitle:(NSString *)title{
// YOU CODE///
}
@end

This may the issue. I have solved by removing this category - (void)setTitle:(NSString *)title.

Note: From iOS 8, UIAlertViewController is inherited from UIViewController. If you use category method, it will be effect on UIAlertView & UIActionSheet titles.

You can refer apple docs at UIAlertController Class Reference



回答2:

It should be noted, that UIAlertView and UIActionSheet is deprecated in iOS 8. You can check out this question or the apple link. May be it will help you.



回答3:

You can use following code using UIAlerController for XCode 6 and IOS 8

UIAlertController * alert=   [UIAlertController
                                 alertControllerWithTitle:@"Title"
                                 message:@"Your Message"
                                 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];

For ActionSheet

UIAlertController * alert=   [UIAlertController
                                     alertControllerWithTitle:@"Title"
                                     message:@"Your Message"
                                     preferredStyle:UIAlertControllerStyleActionSheet];