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]; } }
An object that displays an alert message to the user.
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".
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With