At some point you will want to present a list of items to your users and prompt them to select one. Whilst a spinner is an OK option I prefer the Alert Controller. It’s simple to use and doesn’t take up any screen space until you need it.

1. Create a new UIAlertController and specify that this is a preferred style of “.actionSheet”. Action sheet implies we’re going to present a whole bunch of options:

2. Add some actions to the alert:

Note that you can add as many actions as you like.

3. Finally you need to show the action. This is usually performed in your view controller class (hence the “self” ):

Optionally you can specify a further action once the alert has been shown.

The alert controller is very useful when requesting your user to select from a medium sized list of items.

How to Show an Alert with a List of Items in Swift 4 and iOS 12
Tagged on:     

2 thoughts on “How to Show an Alert with a List of Items in Swift 4 and iOS 12

  • June 30, 2017 at 4:22 pm
    Permalink

    Works for me! Tks! 🙂

    Reply
  • December 22, 2017 at 11:36 pm
    Permalink

    Needs a popoverPresentation Controller in for iPad

    if let popoverController = alert.popoverPresentationController {

    popoverController.sourceView = self.view
    popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
    popoverController.permittedArrowDirections = []

    }

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Share This

Get your FREEapp monetisation flowchart!

Use our epic flowchart to help you find the money in your idea! If you're thinking of making an app then this is vital information!


You have subscribed! Please check your email to confirm this subscription and to receive your item!