UITableView分组显示每个部分中的新信息
我有一组评论,我输出到分组表中。当我将sections方法发送到[array count]时,我希望每个review都在它自己的tableview节中,它只是为数组中的许多项重复相同的组。任何想法,我怎么能做到这一点?我希望这是有道理的。由于UITableView分组显示每个部分中的新信息
- 编辑 -
加什么,我想达到的图片和cellForRow /科/ DidSelectRowMethod的 我希望这个澄清的一切
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *CellIdentifier = @"Cell";
CustomCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.primaryLabel.text = [object objectForKey:@"comment"];
if([[object objectForKey:@"rating"] isEqualToString:@"0"])
{
cell.myImageView.image = [UIImage imageNamed:@"rating_0.png"];
}
if([[object objectForKey:@"rating"] isEqualToString:@"1"]) {
cell.myImageView.image = [UIImage imageNamed:@"rating_1.png"];
}
if([[object objectForKey:@"rating"] isEqualToString:@"2"])
{
cell.myImageView.image = [UIImage imageNamed:@"rating_2.png"];
}
if([[object objectForKey:@"rating"] isEqualToString:@"3"])
{
cell.myImageView.image = [UIImage imageNamed:@"rating_3.png"];
}
if([[object objectForKey:@"rating"] isEqualToString:@"4"])
{
cell.myImageView.image = [UIImage imageNamed:@"rating_4.png"];
}
if([[object objectForKey:@"rating"] isEqualToString:@"5"])
{
cell.myImageView.image = [UIImage imageNamed:@"rating_5.png"];
}
return cell;
}
// Override if you need to change the ordering of objects in the table.
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath
{
return [self.objects objectAtIndex:indexPath.row];
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PFObject *object = [self.objects objectAtIndex:indexPath.row];
Review *review = [[Review alloc] initWithNibName:@"Review" bundle:nil];
review.Name = [object objectForKey:@"userId"];
NSLog(@"%@",[object objectForKey:@"userId"]);
review.rating = [object objectForKey:@"rating"];
review.comments = [object objectForKey:@"comment"];
[self.navigationController pushViewController:review animated:YES];
[review release];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.objects count];
}
既然你希望每个审阅都在一个单独的组中,您必须使用索引路径的部分而不是数组索引的行(由于每部分只有一行,因此该行始终为0):
// Override if you need to change the ordering of objects in the table.
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath
{
return [self.objects objectAtIndex:indexPath.section];
}
完美!谢谢 – Bradley 2012-04-25 14:06:54
只需返回1为numberOfRowsFor每个部分。 添加我定的代码在你的代码
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
这意味着每节只有1个单元格或行。我希望这是你想要达到的目标。 (每个审查现在有它自己的部分)
这意味着每个部分只有1个单元格或行。我希望这是你想要达到的目标。 (每个评论现在都有它自己的部分) – 2012-04-25 10:48:55
你可以发布一些代码,使问题会变得更加清晰。 – Minakshi 2012-04-25 09:35:55
作为一个旁注...你可以用'cell.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@“rating _%@。png”,[object objectForKey:@“rating” ]]];' – Alladinian 2012-04-25 11:01:29