Не выводит label на экран в tableviewcontroller swift

Пытался сделать ToDo list на свифте. Вроде все правильно но почему-то не выводит label на экран приложения Вот код TableViewController.swift

import UIKit

class TableViewController: UITableViewController {

var arraytask: [TaskItem] = []

override func viewDidLoad() {
    super.viewDidLoad()

    
}

override func viewWillAppear(_ animated: Bool) {
    let defaults = UserDefaults.standard
    
    do {
        if let data = defaults.data(forKey:"taskItemArray"){
            let array = try JSONDecoder().decode([TaskItem].self, from:data)
            
            arraytask = array
        }
    } catch {
        print("unable to encode\(error)")
    }
    tableView.reloadData()
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return arraytask.count
}

func SaveTasks(){
    let defaults = UserDefaults.standard
    
    do {
        let encodedata = try JSONEncoder().encode(arraytask)
        
        defaults.set(encodedata, forKey:"taskItemArray")
    } catch {
        print("unable to encode\(error)")
    }
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell.init(style: .default, reuseIdentifier: "cell")

    cell.textLabel?.text = arraytask[indexPath.row].name
    
    if arraytask[indexPath.row].isComplete{
        cell.accessoryType = .checkmark
    } else {
        cell.accessoryType = .none
    }
    

    return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    arraytask[indexPath.row].isComplete.toggle()
    tableView.reloadData()
    SaveTasks()
}


/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    // Return false if you do not want the specified item to be editable.
    return true
}
*/



override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        arraytask.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)
        SaveTasks()
    } else if editingStyle == .insert {
         
    }    
}


/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {

}
*/

/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    // Return false if you do not want the item to be re-orderable.
    return true
}
*/

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destination.
    // Pass the selected object to the new view controller.
}
*/

}


Ответы (1 шт):

Автор решения: Oleg Soloviev

Код вполне рабочий. Проверьте в сториборд, что к нужному экрану привязан класс TableViewController:

введите сюда описание изображения

→ Ссылка