How to use UIAlertController

I am trying to use this code in a Pacman game that I got from some website, but I had to change the UIAlertView to UIAlertController, except that in the following code there are two errors that I don’t know how to fix (I really new to programming and feel like this is really a newbie question - sorry !!)

The first error is line 4: Unknown class method to prevent selection of ControllerWithTitle

Second error: Last line: no visible interface declares a "show" selector

Thanks!!!

- (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]; } } 
+5
source share
2 answers

Please check the following code:

 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]; 
+18
source

Check this 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]; 
+9
source

Source: https://habr.com/ru/post/1264096/


All Articles