Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios moveRowAt使用域对TableView重新排序_Ios_Swift_Uitableview_Realm - Fatal编程技术网

Ios moveRowAt使用域对TableView重新排序

Ios moveRowAt使用域对TableView重新排序,ios,swift,uitableview,realm,Ios,Swift,Uitableview,Realm,我有一个领域模型: class ShoppingListItem: Object { @objc dynamic var department: String = "" var item = List<ShoppingItem>() } class ShoppingItem: Object { @objc dynamic var name: String = "" @objc dynamic var check

我有一个领域模型:

class ShoppingListItem: Object {
    @objc dynamic var department: String = ""
    var item = List<ShoppingItem>()
}

class ShoppingItem: Object {
    @objc dynamic var name: String = ""
    @objc dynamic var checked: Bool = false
    @objc dynamic var sortingIndex = 0
}

领域列表对象的一个很酷的地方是它们保持了它们的顺序

在这种情况下,您不需要sortingIndex属性,因为这些项存储在列表中

class ShoppingListItem: Object {
    @objc dynamic var department: String = ""
    var item = List<ShoppingItem>() <- order is maintained
}
或者使用超级简单移动将对象从一个索引移动到另一个索引

itemList.move(from: 5, to: 1)
class ShoppingListItem: Object {
    @objc dynamic var department: String = ""
    var item = List<ShoppingItem>() <- order is maintained
}
itemList.remove(at: 5) //remove the shoppingItem object at index 5
itemList.insert(shoppingItem, at: 1) //insert the object at index 1
itemList.move(from: 5, to: 1)