HomeiOS Developmentios - use an UIContextualAction in a cell to ship CoreData...

ios – use an UIContextualAction in a cell to ship CoreData strings to an textfield placeholder


I’ve an inventory in a tableview. The cells are full of knowledge from CoreData. So as to add new knowledge I’ve one other ViewController.

ViewControllerAdd

To ship the CoreDataContainer to the subsequent ViewController:

override func put together(for segue: UIStoryboardSegue, sender: Any?) {
    if let nextVC = segue.vacation spot as? ViewControllerAdd {
        nextVC.container = container
    }
}

So as to add the buttons for the cell:

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(type: .damaging, title: nil) { (motion, view, completionHandler) in
        let row = indexPath.row
        self.context.delete(ViewController.liste[row])
        ViewController.liste.take away(at: row)
        tableView.deleteRows(at: [indexPath], with: .automated)
        self.syncOrder()
        self.printData()
        completionHandler(true)
    }
    
    deleteAction.backgroundColor = .systemRed
    deleteAction.picture = UIImage(systemName: "trash.fill")
    
    let editAction = UIContextualAction(type: .damaging, title: nil) { (motion, view, completionHandler) in
        //TODO: Bearbeitung der Daten. Am besten zum ViewControllerAdd. In die leeren Textfields die Daten eintragen bzw. clear
        //TODO: hinterlegen.
        self.performSegue(withIdentifier: "ViewControllerAdd", sender: self)
        print("Edit-Button")
        completionHandler(true)
    }
    
    editAction.backgroundColor = .systemYellow
    editAction.picture = UIImage(systemName: "slider.horizontal.3")
    
    let configuration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
    
    return configuration
}

I attempt to use to fill the textfield.placeholder with the information of CoreData. It ought to load the current knowledge from the container. So I can edit the current knowledge to CoreData I reserve it once more.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments