我试图做到这一点,所以当我按下按钮时,我可以添加单元格的文本和日期。对于日期部分,我尝试查看其他Pod或Swift Manager软件包,但找不到任何东西。 到目前为止,这是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)
}
And here is the simulator with what I have so far.
谢谢!