Momentan habe ich Probleme, meine Tabellenansichten in der richtigen Reihenfolge zu bestellen. Im Moment ändern sie nicht die Reihenfolge, egal was passiert. Ich bin mir nicht sicher, was ich hinzufügen soll, um das zu beheben.TableViews nach spätester Zeit bestellen
import UIKit
class ListNotesTableViewController: UITableViewController {
var notes = [Note](){
didSet{
tableView.reloadData();
}
}
override func viewDidLoad() {
super.viewDidLoad()
notes = CoreDataHelper.retrieveNotes()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return notes.count;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath : IndexPath) ->ListNotesTableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "listNotesTableViewCell", for: indexPath) as! ListNotesTableViewCell
let row = indexPath.row
let note = notes[row]
cell.noteTitleLabel.text = note.title
cell.notePreview.text = note.content;
cell.noteModificationTimeLabel.text = note.modificationTime?.convertToString()
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier {
if identifier == "displayNote" {
print("Table view cell tapped")
let indexPath = tableView.indexPathForSelectedRow!
let note = notes[indexPath.row]
let displayNoteViewController = segue.destination as! DisplayNoteViewController
displayNoteViewController.note = note
} else if identifier == "addNote" {
print("+ button tapped")
}
}
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
CoreDataHelper.delete(note: notes[indexPath.row])
notes = CoreDataHelper.retrieveNotes()
}
}
@IBAction func unwindToListNotesViewController(_ segue: UIStoryboardSegue){
self.notes = CoreDataHelper.retrieveNotes()
}
}
Warum sortieren Sie nicht während des CoreData-Abrufs? – Larme