swift - Swift 5:按下按钮时如何添加文本和日期?
问题描述
我正在努力做到这一点,所以当我按下按钮时,我可以添加单元格的文本和日期。对于日期部分,我尝试查看不同的 Pods 或 Swift Manager Packages 但找不到任何东西。这是到目前为止 addButtonPressed 的代码。我想添加代码,以便我也可以添加日期:
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
var textField = UITextField()
let alert = UIAlertController(title: "Create New Category", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "Add", style: .default) { (action) in
let newProduct = Product(context: self.context)
newProduct.name = textField.text
self.products.append(newProduct)
self.saveProducts()
}
alert.addTextField { (alertTextField) in
alertTextField.placeholder = "Create new category"
textField = alertTextField
}
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
谢谢!
解决方案
推荐阅读
- git - 是否有命令可以查看您对 repo 拥有哪些访问权限?
- amazon-web-services - 没有 INSERT_XID(隐藏元数据)列数据的 RedShift Deep Copy
- reporting-services - 是否可以使用 URL 将 SSRS 报告 Excel 文件导出到特定目标文件夹
- python - 在 discord.py 中赋予角色
- javascript - 如何使用“locale storage”创建保存和加载功能?
- java - 如果用户已经给了它,如何停止将用户给定的对象添加到数组列表中?
- css - 为什么我的 vuejs 依赖项 maz-ui maz-phone-number-input 格式不正确?
- python - 使用多个数据集创建 seaborn 散点图矩阵 (PairGrid)
- java - 初始化嵌套对象
- javascript - HTML/JS 表单无法正确导入/导出 txt