Hi, I am in the process of building a to-do app and am getting stuck. My first view controller displays a table view with tasks in each cell, and has an accessory button. When the button is clicked, a new view controller is displayed, with again a table view. The add button (a navigation bar item) once again opens a new view controller where the user can add in a task name, with an add button at the bottom. When the button is clicked the following code runs:
@IBAction func addAction(_ sender: Any) {
if taskNameOutlet.text != "" {
delegate?.addSubTask(nameOfSubTask: taskNameOutlet.text!)
navigationController?.popViewController(animated: true)
print(taskNameOutlet.text!)
}
}
I use the protocol, which my view controller conforms to:
protocol AddSubTask {
//Changed the following two lines
func addSubTask(nameOfSubTask: String)
}
I then have the following code in the view controller:
func addSubTask(nameOfSubTask: String) {
print("test")
tableView.reloadData()
}
I want to add more in that chunk of code (e.g. tasks[indexPath].miniTaskArr.append(miniTask(name2: nameOfSubTask))), yet the string “test” isn’t even being printed to my console.
How do I fix this? I just want the add button to delegate the view controller to call the func addSubTask so I can append values into an array. Thanks, Annique