1

我有一组评论,我将它们输出到一个分组表中。当我将sections 方法发送到[array count] 时,我希望每条评论都在它自己的tableview 部分中,它只是重复相同的组,因为数组中有许多项目。知道我该怎么做吗?我希望这是有道理的。谢谢

- 编辑 -

添加了我想要实现的图片和 cellForRow/Section/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];
}
4

2 回答 2

2

只需为每个部分的 numberOfRowsFor 返回 1。在您的代码中添加我给定的代码

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   return 1;
 }

这意味着每个部分只有 1 个单元格或行。我希望这是您想要实现的目标。(每条评论现在都有自己的部分)

于 2012-04-25T10:46:57.807 回答
1

由于您希望每个评论都在一个单独的组中,因此您必须使用索引路径的部分而不是数组索引的行(该行将始终为 0,因为每个部分只有一行):

// Override if you need to change the ordering of objects in the table.
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath 
{ 
    return [self.objects objectAtIndex:indexPath.section];
}
于 2012-04-25T10:10:18.757 回答