我正在使用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 \ n \ testado \ \”里约热内卢\“; \ n exercicio1 = \”\“; \ n exercicios =(\ n \”{\ n Title = \\“Rosca no Pulley \\” ; \ n} \“,\ n \”{\ n标题= \\“Rosca no Pulley \\”; \ n} \“\ n); \ n nascimento = \”12/02/1888 \“; \ n nome = Jorge; \ n pais = Brasil; \ n sobrenome = Junior; \ n telefone = \“(21)9999-9999 \”; \ n username = \“blabla@globo.com \”; \ n}“
答案 0 :(得分:0)
如果您正在使用PFQueryTableViewController,则不需要执行findObjects
queryForTable会自动将每个对象发送到- (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];