2017-02-11 4 views
4

J'essaie d'utiliser ce code dans un jeu Pacman que j'ai obtenu à partir d'un site Web, mais j'ai dû changer UIAlertView en UIAlertController, sauf que le code suivant a deux erreurs que je ne sais pas réparer (je suis vraiment nouveau à la programmation et se sentir comme cela est une question vraiment débutant - désolé !!)comment utiliser UIAlertController

Première erreur est la ligne 4: méthode de classe Non connu pour sélecteur alertControllerWithTitle

Deuxième erreur Dernière ligne: pas d'interface visible déclare le sélecteur "show"

Merci !!!

- (void)collisionWithExit: (UIAlertController *)alert { 

if (CGRectIntersectsRect(self.pacman.frame, self.exit.frame)) { 

    [self.motionManager stopAccelerometerUpdates]; 

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Congratulations" 
                message:@"You've won the game!" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil 
              preferredStyle:UIAlertControllerStyleAlert]; 
    [alert show]; 

    } 

} 
+0

'AlertView' est depricated dans iOS 9 donc au lieu de vous devez utiliser' UIAlertController' avec plus d'options . – vaibhav

+0

[lien utile pour vous] (https://www.google.co.in/?gws_rd=ssl#q=uialertview+deprecated+ios+9+), cherchez un peu :) – vaibhav

Répondre

13

S'il vous plaît vérifier le code suivant:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
          message:@"This is an alert." 
          preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) {}]; 

[alert addAction:defaultAction]; 
[self presentViewController:alert animated:YES completion:nil]; 
7

Consultez ci-dessous le code

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Name" message:@"YOUR ALERT MESSAGE" preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) 
             { 
              //BUTTON OK CLICK EVENT 
             }]; 
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 
    [alert addAction:cancel]; 
    [alert addAction:ok]; 
    [self presentViewController:alert animated:YES completion:nil];