我使用 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}"