swift - 我需要创建一个弹出菜单,当按下 Collection View 单元格时,我可以在其中更改 Collection View 中的数据。

标签 swift xcode label popupmenu

基本上,这个问题已经说明了一切。我考虑过一个警报,但我实际上需要在里面有一个文本框,并且能够将文本保存到标签中。关于我应该在这方面使用什么的任何想法?我不想在导航中创建新的 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/

相关文章:

java - 如何在 onclick 方法中重置标签上的所有内容

ios - String 不符合 NSarray Swift 中的 AnyObject 类型

c++ - apple mach o 链接器错误创建基本 AI CC 插件

iphone - 在 Xcode 中的项目之间共享代码

label - Gnuplot:用图像绘制时不显示标签

ios - 超出父 View 时隐藏标签/按钮

ios - 基于另一个数组 Swift 的过滤来过滤数组

ios - xcode 8模拟器先白后黑

InterfaceBuilder 中带有自定义 accessoryView 的 iOS UITableViewCell

iphone - 如何跟踪仪器上的 UI 事件