Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use UIAlertController

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

The first error is in line 4: No known class method for selector alertControllerWithTitle

A second error is in the last line: no visible interface declares the selector show

- (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];     } } 
like image 472
Howie Chowie Avatar asked Feb 11 '17 06:02

Howie Chowie


People also ask

What is a UIAlertController?

An object that displays an alert message to the user.

How do I display an action sheet in Swift?

Enter Swift as Language and Storyboard as User Interface. Choose Next. Go to the Storyboard, drag a Button from the Object Library to the View Controller inside the Storyboard. Double-click the Button and give it a title of"Display Action Sheet".


1 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]; 
like image 105
Anirban iOS Avatar answered Oct 08 '22 16:10

Anirban iOS