【发布时间】:2019-05-29 23:40:55
【问题描述】:
我使用 parse.com 作为数据库,并且我在单元格中需要的数据似乎已正确传输到 nsarray,尽管我无法在我的表中显示它。
这是查询数据库的方法。
- (PFQuery *)queryForTable {
PFQuery *exerciciosQuery = [PFQuery queryWithClassName:@"ExerciciosPeso"];
[exerciciosQuery whereKey:@"usuario" equalTo:[PFUser currentUser]];
[exerciciosQuery includeKey:@"exercicio"];
// execute the query
_exerciciosArray = [exerciciosQuery findObjects];
for(PFObject *o in _exerciciosArray) {
PFObject *object = o[@"exercicio"];
NSLog(@"PFOBJECT %@", object);
NSLog(@"%@", o);
}
NSLog(@"%@", _exerciciosArray);
return exerciciosQuery;
}
Grupo = Biceps;
descricao = "descricao alternada";
titulo = "Rosca alternada";
Peso = 10;
exercicio = "<Exercicios:Iv2XB4EHSY>";
usuario = "<PFUser:W9ifgHpbov>";
Grupo = Biceps;
descricao = descricao;
titulo = "Puxada Reta";
Peso = 20;
exercicio = "<Exercicios:nmqArIngvR>";
usuario = "<PFUser:W9ifgHpbov>";
Grupo = Biceps;
descricao = "Fazer rosca";
titulo = "Rosca no Pulley";
Peso = 30;
exercicio = "<Exercicios:CXecX4DJiO>";
usuario = "<PFUser:W9ifgHpbov>";
Grupo = Biceps;
descricao = "em pe descricao";
titulo = "Biceps na corda";
Peso = 40;
exercicio = "<Exercicios:6slVOQnj3y>";
usuario = "<PFUser:W9ifgHpbov>";
好的,作为大纲中的淋浴,我的查询成功地填充了一个数组,其中包含来自链接的数据库中不同表的四个对象。但我想这并不重要。
我需要做的是填充我的单元格,四行,因为我有四个带有特定键的项目。我想按行显示,分配给“titulo”和“Peso”的值似乎都在查询中正确返回。
当我使用以下代码尝试填充 for 循环内的单元格时,它只会添加四行相同的项目。
- (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];
}
for(PFObject *o in _exerciciosArray) {
PFObject *object = o[@"exercicio"];
cell.textLabel.text = [object objectForKey:@"titulo"];
}
return cell;
}
当我删除 for 循环并添加以下行时,我的表中没有任何内容。
object = [_exerciciosArray objectAtIndex:indexPath.row];
cell.textLabel.text = [object objectForKey:@"titulo"];
我已经尝试了很多东西,我敢肯定这是小事。请帮忙。
【问题讨论】:
标签: ios objective-c uitableview parse-platform