【问题标题】:UIAlertView is deprecated : first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyleUIAlertView 已弃用:首先在 iOS 9.0 中弃用 - UIAlertView 已弃用。将 UIAlertController 与首选样式一起使用
【发布时间】:2017-01-03 09:00:34
【问题描述】:

如何更改适合上述iOS 9 的obj c 代码?当我将 X Code 更新到 8.2.1 时出现此错误。代码如下

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"Continue"]){
        NSLog(@"Continue...");
        [self performSegueWithIdentifier:@"createlogin" sender:self];
    }
}

错误:

UIAlertView 已弃用:在 iOS 9.0 中首次弃用 - UIAlertView 已弃用。将 UIAlertController 与 preferredStyle 一起使用 UIAlertControllerStyleAlert 代替

谢谢。

【问题讨论】:

标签: ios objective-c xcode


【解决方案1】:
 UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Add Title" message:@"Add Message" preferredStyle:UIAlertControllerStyleAlert];
     UIAlertAction * actionOK = [UIAlertAction actionWithTitle:@"Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        //Here Add Your Action
                    }];
     UIAlertAction * actionCANCEL = [UIAlertAction actionWithTitle:@"Second Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        //Add Another Action
                    }];


               [alert addAction:actionOK];
             [alert addAction:actionCANCEL];

   [self presentViewController:alert animated:YES completion:nil];

如果有需要请使用此方法,更多信息请使用此链接http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/

【讨论】:

    【解决方案2】:

    使用此代码

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * continueButton = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
          [self performSegueWithIdentifier:@"createlogin" sender:self];
      }];
     UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
    
      }];
    [alert addAction:continueButton];
    [alert addAction:cancelButton];
    [self presentViewController:alert animated:YES completion:nil];
    

    【讨论】:

      【解决方案3】:

      试试这个:

      UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Your message title"
                                                                                      message:@"Enter your message here."
                                                                               preferredStyle:UIAlertControllerStyleAlert];
      
      UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
       {
           NSLog(@"Ok Action");
       }];
      UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
       {
           NSLog(@"Cancel Action");
      }];
      
      [controller addAction:okAction];
      [controller addAction:cancelAction];
      [self presentViewController:alertController animated:YES completion:nil];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-31
        • 2016-07-23
        • 2016-01-14
        • 1970-01-01
        • 2015-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多