如何保持Realm数据与输入的顺序相同 [英] How to keep Realm data in the same order as entered

查看:154
本文介绍了如何保持Realm数据与输入的顺序相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,需要在该应用程序中按输入顺序保持数据顺序.数据被输入到List属性中.一切正常,直到我必须删除一个项目.当删除发生时,列表上的最后一项将代替已删除的项. UITableView显示正确数量的项目,但未与领域列表同步.

I have an application where I need to keep the data in the same order as it is entered. The data is entered into a List property. Everything works great until I have to delete an item. When the delete occurs the last item on the List takes the place of the one that was deleted. The UITableView shows the correct number of items but is not synchronized with the realm List.

例如,如果我有数据:

1、2、3、4、5、6

1, 2, 3, 4, 5, 6

然后我删除:

3

领域数据如下:

1、2、6、4、5

1, 2, 6, 4, 5

tableview看起来像这样:

The tableview looks like this:

1、2、4、5、6

1, 2, 4, 5, 6

领域数据的期望结果将与tableview输出匹配.

The desired result of the realm data would match the tableview output.

在删除项目之后,有什么方法可以保持数据顺序不变吗?

Is there any way to keep the order of the data from changing after items are deleted?

推荐答案

领域中的对象本质上是无序的.如果希望按控制的特定顺序检索对象,可以通过将它们插入对象的List属性中,或对用于检索它们的Results进行排序来实现.

Objects in a Realm are inherently unordered. If you wish to retrieve objects in a specific order that you control, you can do so by inserting them into a List property of an object, or by sorting the Results that you use to retrieve them.

这篇关于如何保持Realm数据与输入的顺序相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆