我正在做的是在我的 Parse 查询中,我检查过去 7 天内哪些帖子被选中标记(喜欢)。然后我删除那些没有的日期。这工作正常。现在我的问题是我需要在我的 UITableView 中按照数组中有多少日期的降序对它们进行排序,但是我的 sortedArrayUsingComparator 不起作用。我是Objective C的新手,所以它可能很容易但很容易。这是我的代码
- (PFQuery *)queryForParse {
PFQuery *query1 = [PFQuery queryWithClassName:self.parseClassName];
//[query1 selectKeys: [NSArray arrayWithContentsOfFile:[ NSString @"checkMark"]]];
[query1 whereKey:@"location" nearGeoPoint:[PFGeoPoint geoPointWithLatitude:[LocationController sharedSingleton].locationManager.location.coordinate.latitude longitude:[LocationController sharedSingleton].locationManager.location.coordinate.longitude] withinMiles:50];
[query1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
placesArray = [[NSMutableArray alloc] initWithArray:objects];
NSMutableArray *toDelete = [NSMutableArray array];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
for (PFObject *tempObject in placesArray){
checkDates = [[NSMutableArray alloc] initWithArray:[tempObject objectForKey:@"checkMarkDates"]];
for (NSString *dateString in checkDates) {
NSDate *date = [dateFormat dateFromString: dateString];
if ([date timeIntervalSinceNow] > -604800){
[toDelete addObject:dateString];
}
}
[checkDates removeObjectsInArray:toDelete];
[tempObject removeObjectsInArray:checkDates forKey:@"checkMarkDates"];
sortedArray = [placesArray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSUInteger *first = [[obj1 objectForKey:@"checkMarkDates"] count];
NSNumber *f = [[NSNumber alloc] initWithInteger:first];
NSUInteger *second = [[obj2 objectForKey:@"checkMarkDates"] count];
NSNumber *s = [[NSNumber alloc] initWithInteger:second];
return [f compare:s];
}];
}
NSLog(@"%@", sortedArray);
}
[placesTable reloadData];
}];
return query1;
}