使用 query.limit 对 Parse 的排序结果无法按预期工作 [英] Sorting results from Parse is not working as expected with query.limit

查看:58
本文介绍了使用 query.limit 对 Parse 的排序结果无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我将查询的限制设置为 10,然后我想获取数据集中的最后 10 个结果并按时间升序排序!好的,我知道我可以添加:

I set a limit for my query to be 10 for example and then I want to get the last 10 results in the data set AND sorted with ascending time! Okay I know I can add:

[messages addDescendingOrder:@"createdAt"];
//OR
[messages addAscendingOrder:@"createdAt"];

但是这是在做的是获取前10条记录还是后10条记录...它不是自己对结果进行排序!!升序基本上是设置结果从哪里开始......从底部或从顶部.但我希望返回的结果集是最后 10 个结果,并且这些结果按升序排列.相反,我得到了最后 10 个结果,但在表格中,我在顶部有最新的结果,而集合中最旧的结果是表格中的最后一个单元格......我想要相反的......

But what this is doing is that it is getting the first 10 records or the last 10 records... It is not sorting the results themselves!! The ascending order is basically setting where the results are going to start... From bottom or from top. But I want the results set coming back to be last 10 results and those results in ascending order. Instead, I am getting last 10 results but in the table I have the newest one on the top and the oldest one in the set to be the last cell in the table... I want the reverse of that...

有没有办法让 Parse 处理这个问题,而不是在设备本身上做逻辑?非常感谢任何帮助.

Is there a way to have Parse take care of this rather than making logic to do it on the device itself? Any help is greatly appreciated.

推荐答案

好吧,对于遇到类似问题的其他人,解决方案是将您从 Parse 的查询中获得的结果数组反向.完毕 :)快乐编码!

Ok so for others who are having a similar problem, the solution is to reverse the results array that you get from the query back from Parse. Done :) Happy Coding!

我使用了在 StackOverflow 上有关反转数组的不同问题中找到的代码,但这里又是代码:

I used the code that I found in a different question about reversing arrays on StackOverflow but here is the code again:

@implementation NSArray (Reverse)

- (NSArray *)reversedArray {
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self count]];
    NSEnumerator *enumerator = [self reverseObjectEnumerator];
    for (id element in enumerator) {
        [array addObject:element];
    }
    return array;
}

@end

@implementation NSMutableArray (Reverse)

- (void)reverse {
    if ([self count] == 0)
        return;
    NSUInteger i = 0;
    NSUInteger j = [self count] - 1;
    while (i < j) {
        [self exchangeObjectAtIndex:i
                  withObjectAtIndex:j];

        i++;
        j--;
    }
}

@end

这篇关于使用 query.limit 对 Parse 的排序结果无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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