Your table view is sorted based on a name. Given that the names are fixed, if you reorder cells 'by hand' and then return to the table view, the sorting based on the name is reestablished.
To get what you want you'll need to add a field to your Core Data model called something like sortIndex
. You then sort the table with a sortDescriptor
based on sortIndex
; you can initialize sortIndex
to the creation order. When the User reorders cells through the UI, you'll also change the sortIndex
for all the impacted cells/managed-objects. Then, since sortIndex
is part of the Core Data model, when the User ends and restarts your App, their preferred sorting will be reestablished.
Sometimes, for modeling reasons, you don't want to include a sortIndex
directly in some managed object. For example, a Person
has first and last names but not a sortIndex
(in fact). You can create an association, perhaps a DisplayPreferences
managed object, with a one-to-one mapping between a Person
and a DisplayPreferences
and having a sortIndex
in DisplayPreferences
.