【问题标题】:How to use UIAlertView with iOS 8? [duplicate]如何在 iOS 8 中使用 UIAlertView? [复制]
【发布时间】:2015-01-12 05:35:10
【问题描述】:

自 iOS8 发布以来我一直在使用 AlertView,但在 iOS8 发布后 UIAlertView 被 UIAlertViewController 取代。那么如何将其用作 UIAlertView。

【问题讨论】:

  • 您好,欢迎来到 Stack Overflow。你能给我们更多的信息吗?另外,请编辑您的问题并添加您尝试使其工作的代码,并解释您遇到的错误(如果有,请包括任何相关的日志文件条目)。还请告诉我们您对该主题进行了哪些研究(这样我们就不会重复您的努力)。谢谢

标签: ios iphone ipad ios8 xcode6


【解决方案1】:

ios8 中 Swift 中的 AlertView

var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

【讨论】:

    【解决方案2】:
    UIAlertController * myAlert=   [UIAlertController
                                    alertControllerWithTitle:@"My Alert"
                                    message:@"put a message here"
                                    preferredStyle:UIAlertControllerStyleAlert];
    
    [self presentViewController:MyAlert animated:YES completion:nil];
    

    【讨论】:

      【解决方案3】:
      if ([UIAlertController class])
      {
          // use UIAlertController
          UIAlertController *alert= [UIAlertController
                                        alertControllerWithTitle:@"Enter Folder Name"
                                        message:@"Keep it short and sweet"
                                        preferredStyle:UIAlertControllerStyleAlert];
      
          UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action){
                                                         //Do Some action here
      
      
                                                     }];
          UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
      
                                                             NSLog(@"cancel btn");
      
                                                             [alert dismissViewControllerAnimated:YES completion:nil];
      
                                                         }];
      
          [alert addAction:ok];
          [alert addAction:cancel];
      
      
      
          [self presentViewController:alert animated:YES completion:nil];
      

      使用此代码

      【讨论】:

      • 这个很有帮助。
      猜你喜欢
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多