Home > Articles > Mobile Application Development & Programming

Displaying Alerts in iOS 8

  • Print
  • + Share This
With every new release, Apple's operating system grows more powerful and a better fit for all its applicable devices. But changes in the OS mean extra work for software developers, who must ensure that their legacy programs still run and that new products fit the new version. Wei-Meng Lee describes the new UIAlertController class in iOS 8 and how it can improve your program's ability to display messages and get input from users.
Like this article? We recommend

With the launch of the iPhone 6 and iPhone 6 Plus, Apple also released the iOS 8 platform. Among the many updates in this version of iOS are some subtle changes that affect how alerts are displayed. In this article, I will discuss the new UIAlertController class and the classes that it replaces.

UIAlertView and UIActionSheet: Deprecated

If you've ever programmed iOS apps, no doubt you're familiar with the UIAlertView class. You most likely used this class in your first iOS “Hello World!” application. In iOS 8, the UIAlertView class is still available, but deprecated. You should avoid using it, as future versions of iOS might not support it.

The following example shows the UIAlertView in iOS 8, written in Swift:

var alertView = UIAlertView(
  title:"Hello, iOS8",
  message:"I am deprecated!",


Figure 1 shows how the UIAlertView class looks.

Figure 1

Figure 1 The venerable UIAlertView class, deprecated in iOS 8.

To learn which button the user has tapped, you need to implement the UIAlertViewDelegate protocol and implement the following method:

func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
  println("Button click: \(buttonIndex)")

Like the UIAlertView class, the UIActionSheet class is deprecated in iOS 8. The following code creates an action sheet in iOS 8:

var actionSheet = UIActionSheet(
  title: "Are you sure?",
  cancelButtonTitle: "Cancel",
  destructiveButtonTitle: "Delete",
  otherButtonTitles: "Delete with backup")


Figure 2 shows the Action Sheet in action.

Figure 2

Figure 2 The UIActionSheet class is deprecated in iOS 8.

  • + Share This
  • 🔖 Save To Your Account