gpt4 book ai didi

iphone - UITableView 分组显示每个部分的新信息

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:36 24 4
gpt4 key购买 nike

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

--编辑--

添加了我想要实现的图片和 cellForRow/Section/DidSelectRowMethod 的图片我希望这能澄清一切

enter image description here

- (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];
}

最佳答案

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

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

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

关于iphone - UITableView 分组显示每个部分的新信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10312924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com