0

I have created a drop down with text and button, when the drop down button is clicked the data is populated in the UIAlertController of type action sheet.

Now to replicate drop down behavior need to set the text of textfield as the clicked UIAlertActon title.

But I am not able to find any way to fetch the title and set it as text of UITextField. I am using swift.

Please suggest.

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
RPP
  • 55
  • 6

1 Answers1

2

When you create your UIAlertAction, you can add a handler which gets called when the button is tapped. Your action gets passed into the handler, so you can access its title property there:

let myAction = UIAlertAction(title: "Option 1", style: .Default) { action in
    println(action.title)
}

You can see this in the docs for UIAlertAction.

James Frost
  • 6,960
  • 1
  • 33
  • 42