基本上,这个问题已经说明了一切。我考虑过一个警报,但我实际上需要在里面有一个文本框,并且能够将文本保存到标签中。关于我应该在这方面使用什么的任何想法?我不想在导航中创建新的 View Controller 。我只是想要一个弹出 View 根据需要打开和关闭。
非常感谢所有建议。谢谢!
最佳答案
您可以在alertController中添加一个文本字段。
请引用这个答案https://stackoverflow.com/a/33000328/1754559
let alertController = UIAlertController(title: "Your alert", message: "", preferredStyle: .alert)
let saveAction = UIAlertAction(title: "Save", style: .default, handler: {
alert -> Void in
guard let textField = alertController.textFields?[0] as UITextField else { return }
yourLabel.text = textField.text
})
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: {
(action : UIAlertAction!) -> Void in })
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Whatever"
//Other textField configurations
}
alertController.addAction(saveAction)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
关于swift - 我需要创建一个弹出菜单,当按下 Collection View 单元格时,我可以在其中更改 Collection View 中的数据。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43853951/