Ios 通过检索数据和升序排序来加倍数据

Ios 通过检索数据和升序排序来加倍数据,ios,parse-platform,tableview,Ios,Parse Platform,Tableview,我正在从parse.com检索数据 我想按升序进行设置,但我看到一些数据大约是10倍的两倍,而我只想将每个单元格显示为一个用户名数据 你能看出我做错了什么吗 - (void)viewDidLoad { [super viewDidLoad]; PFUser *currentUser = [PFUser currentUser]; if (currentUser) { NSLog(@"Current user: %@", currentUser.username); } else {

我正在从parse.com检索数据 我想按升序进行设置,但我看到一些数据大约是10倍的两倍,而我只想将每个单元格显示为一个用户名数据

你能看出我做错了什么吗

- (void)viewDidLoad
{
[super viewDidLoad];

PFUser *currentUser = [PFUser currentUser];
if (currentUser) {
    NSLog(@"Current user: %@", currentUser.username);
}

else {
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}


}

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

PFQuery *query = [PFQuery queryWithClassName:@"Aanvragen"];
[query whereKey:@"RecipientIDs" equalTo:[[PFUser currentUser]objectId]];
[query orderByDescending:@"Datum"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }

    else {
        // we found messages
        self.messages = objects;
        [self.tableView reloadData];
        NSLog(@"Retrieved %d messages", [self.messages count]);
    }
}];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.
return [self.messages count];
}

#pragma mark - Table view
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


PFObject *message = [self.messages objectAtIndex:indexPath.row];
cell.textLabel.text = [message objectForKey:@"senderName"];

NSString *fileType = [message objectForKey:@"FileType"];

self.objectId = [message objectId];
NSLog(@" objectId: %@", [self objectId]);

if ([fileType isEqualToString:@"image"]) {
    cell.imageView.image = [UIImage imageNamed:@"icon_image"];
}

else if ([fileType isEqualToString:@"video"]) {
    cell.imageView.image = [UIImage imageNamed:@"icon_video"];
}

else {
    cell.imageView.image = nil;
}
return cell;
}

您应该更改数据模型。与其使用RecipientID并在其中存储objectId字符串,不如创建一个名为recipient的新列,该列是指向用户类的指针,然后将用户对象放入其中。这是创建类之间关系的正确方法:

aanvragen[@"recipient"] = [PFUser currentUser];
现在您可以更改查询约束,如下所示:

[query whereKey:@"recipient" equalTo:[PFUser currentUser]];

每个对象只能得到1个。

有些数据大约是10倍的两倍意味着什么?您是否收到重复的条目?RecipientID是什么类型的列?嗨,是的,我的意思是我收到了20次相同的条目。RecipientID是邮件收件人的objectID。这是每个用户的每条消息>1个recipientID。我是否在tableviewcell中出错?我了解RecipientId列包含的内容。但是它是什么样的专栏呢?可能是字符串数组?或者它只是一个表示用户objectId的字符串?recipientID只是一个表示ReceiveEnde用户objectId的字符串。