0

I'm trying to make it so when I press a button, I can add the cell's text and a date. For the date part, I tried looking at different Pods or Swift Manager Packages but couldn't find anything. Here's is the code so far for the addButtonPressed. I'd like to add code so I can add the date as well:

@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.

Thanks!

Nico Cobelo
  • 557
  • 7
  • 18
  • just add another textfield using a date picker as its inputView https://developer.apple.com/documentation/uikit/uiresponder/1621092-inputview – Leo Dabus Dec 02 '20 at 13:12
  • I think this can help you : https://stackoverflow.com/questions/49547677/swift-ios-adding-date-picker-to-an-alert-in-swift-to-be-saved-to-local-db-using/49550613 – Setar Dec 02 '20 at 13:13
  • What part are you having trouble with? Getting a date from the user? Adding an item to your table view's model that contains a category name and a date? Displaying an entry in your table view that shows both the category name and a formatted date string? – Duncan C Dec 02 '20 at 14:01
  • 1
    @Setar, that actually helped! Thanks! – Nico Cobelo Dec 03 '20 at 21:06

0 Answers0