从CoreData
to检索存储数据时tableView
,文本显示在一个单元格本身中,而不显示另一个单元格。如何获取单个单元格中的文本。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasks.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let task = tasks[indexPath.row]
cell.textLabel?.text = task.name
return cell
}
func getData()
{
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
do{
tasks = try context.fetch(Task.fetchRequest())
}catch{
print("fetching error")
}
}
override func viewWillAppear(_ animated: Bool) {
getData()
tableView.reloadData()
}