If you’re using UIAlertView and targeting your application for iOS 8.3 or higher, you’re probably aware that you’ll get a deprecated compiler warning. The replacement for UIAlertView is actually UIAlertController. The most important thing you need to know is that UIAlertView could have been called anywhere. Now you have to construct a UIAlertController and then present it from a controller. This is similarly how you would call any other presentation view controller.
Now presenting UIPopoverViewController has also been deprecated for a simpler and more consistent API. This migration is also rather easy.
UIAlertController also can substitute UIActionSheet as well. When constructing it all you need to do is feed it the proper enum: either UIAlertControllerStyleAlert or UIAlertControllerStyleActionSheet. For Swift 3.0 you can feed it UIAlertControllerStyle.actionSheet or UIAlertControllerStyle.alert.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
NSString *title = @"My Title"; NSString *message = @"This alert is a good thing for your health!"; UIAlertController *alertController = [UIAlertController alertControllerWithTitle: message:message preferredStyle:UIAlertControllerStyleAlert];