UIAlertView and UIActionSheet not displaying properly in iOS 8

做~自己de王妃 提交于 2019-12-21 05:09:24

问题


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];


来源:https://stackoverflow.com/questions/25947888/uialertview-and-uiactionsheet-not-displaying-properly-in-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!