How to create an Alert View

Here’s how we can create a simple pop-up window via the UIAlertView instance. It can have a title, some info text and several buttons (OK, Cancel, etc). We’ll only deal with one button and not worry about how to read out which button value has been pressed.

This is what a UIAlertView looks like

And here’s how we build this on Objective-C:

This is quite a long block of code so here are the steps:

  • create an instance of the UIAlertView
  • allocate and initiate it with parameters Title, Message, and an array of buttons (cancel and nil if you’re only using a single button to dismiss the view)
  • give the view a style (mandatory)
  • display the view

You can add a \n for a line break inside the window.

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

1 thought on “How to create an Alert View

  1. Here is a shorter version of the code, hopefully more cut-and-paste friendly:

Leave a Reply to Jay Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.