1

我正在从 Web 服务获取数据列表。我希望我的表格只显示包含数据的行数而不是其余的(空行)。下面提到的方法我曾经这样做,但它并不有效,它只会为非空单元格着色。任何人都可以为此指导我。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor grayColor]; 
}

提前致谢。

4

4 回答 4

0

尝试这个:

- (UIView *)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger*)section
{
    UIView *view=[[UIView alloc]init];
    return view;
}

这不会改变框架,但会隐藏空单元格之间的线。我想你想要那个。

于 2013-01-16T07:47:45.537 回答
0

尝试使用这个

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return array.count;

}

其中数组将是您从 Web 服务获取的列表数据数组

于 2013-01-16T09:21:24.760 回答
0

怎么样

if(arrayServ.count > 6)
{
    tableService.frame = CGRectMake(5, 20, 310, 6 * 45);
}
else
{
    tableService.frame = CGRectMake(5, 20, 310, arrayServ.count * 45);
}

而不是分别处理每个案例?

此外,如果有人阅读您的问题,他可能会认为您可能想要隐藏空单元格而不是您想要调整 uitableview 的帧大小。

于 2013-01-16T10:50:05.920 回答
0

最后我得到了解决方案,

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{    
//return 172;
if([arrayServ count] == 1)
{
    tableService.frame = CGRectMake(5, 20, 310, 40);
}

if([arrayServ count] == 2)
{
    tableService.frame = CGRectMake(5, 20, 310, 85);
}

if([arrayServ count] == 3)
{
   // return 172;
    tableService.frame = CGRectMake(5, 20, 310, 130);
}

if([arrayServ count] == 4)
{
    tableService.frame = CGRectMake(5, 20, 310, 175);
}

if([arrayServ count] == 5)
{
    tableService.frame = CGRectMake(5, 20, 310, 220);
}

if([arrayServ count] == 6)
{
    tableService.frame = CGRectMake(5, 20, 310, 265);
}

if([arrayServ count] == 7)
{
    tableService.frame = CGRectMake(5, 20, 310, 310);
}

if([arrayServ count] > 7)
{
    tableService.scrollEnabled = TRUE;
}
return 0;
}
于 2013-01-16T10:09:18.220 回答