如何将 iOS 8.0+ 的类型为 action sheet 的选定 UIAlertController 的标题获取到标签中?

How to get the title of the selected UIAlertController of type action sheet for iOS 8.0+ into a label?

我创建了一个带有文本和按钮的下拉菜单,当单击下拉按钮时,数据会填充到类型为 sheet 的 UIAlertController 中。

现在要复制下拉行为需要将文本字段的文本设置为单击的 UIAlertActon 标题。

但我找不到任何方法来获取标题并将其设置为 UITextField 的文本。我正在使用 swift.

请推荐。

创建 UIAlertAction 时,您可以添加一个处理程序,该处理程序会在点击按钮时调用。您的操作会传递到处理程序中,因此您可以在此处访问其标题 属性:

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

您可以在 docs for UIAlertAction 中看到这个。