0

我使用 parse.com 作为数据库。我的 tableViewController 是一个 PFQueryTableViewController 类,如下所示:

// Override to customize what kind of query to perform on the class. The default is to query for
// all objects ordered by createdAt descending.
- (PFQuery *)queryForTable {
    PFQuery *exerciciosQuery = [PFQuery queryWithClassName:self.parseClassName];
    [exerciciosQuery includeKey:@"exercicios"];
    [exerciciosQuery findObjects];
    _exerciciosArray = [exerciciosQuery findObjects];
    NSLog(@"teste %@", _exerciciosArray);

    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.
    if ([self.objects count] == 5) {
        exerciciosQuery.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }

    return exerciciosQuery;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath object:(PFObject *)object {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    // Configure the cell
    PFObject *exercicios = [_exerciciosArray objectAtIndex:indexPath.row];
    [cell.textLabel setText:[exercicios objectForKey:@"Title"]];

    return cell;
}

我的表不显示任何内容。当我记录 _exerciciosArray 时,它看起来像这样:

{\n cep = \"25553-555\";\n cidade = \"Rio de Janeiro\";\n email = \"blabla@globo.com\";\n endereco = \"Rua Oscar 100/500 \";\n estado = \"里约热内卢\";\n exercicio1 = \"\";\n exercicios = (\n \" {\n Title = \\"Rosca no Pulley\\";\n }\",\n \" {\n Title = \\"Rosca no Pulley\\";\n}\"\n );\n nascimento = \"12/02/1888\";\n nome = Jorge;\n pais = 巴西;\n sobrenome = Junior;\n 电话 = \"(21) 9999-9999\";\n 用户名 = \"blabla@globo.com\";\n}"

4

1 回答 1

0

如果您使用的是 PFQueryTableViewController,则不需要执行findObjectsqueryForTable 将自动发送每个对象,- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {因此您不需要PFObject *exercicios = [_exerciciosArray objectAtIndex:indexPath.row];,因为您已经在方法中接收到 PFObject。

做就是了:

[cell.textLabel setText:[object objectForKey:@"Title"]];

并从中删除queryForTable

[exerciciosQuery findObjects];
_exerciciosArray = [exerciciosQuery findObjects];
于 2014-04-16T15:50:01.000 回答