如何仅更改tableview中最后一个单元格的行高?

时间:2010-07-04 04:56:24

标签: objective-c

在我的表格视图中,我有超过200行,然后通过在最后一个单元格中保持loadmoreresults来管理每页仅显示40行。当用户点击加载时,更多结果显示40个单元格。我更改了行负荷高度导致细胞与其他细胞不同。问题是当没有更多结果时,其他单元格的高度受到loadmoreresults单元格高度的影响我不想影响最后一行高度到其他行。

我写的代码为:

- (NSInteger)tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section
{
ZohoAppDelegate* appDelegate = (ZohoAppDelegate*) [ [UIApplication sharedApplication] delegate];

int maxResults = [appDelegate.invoiceMaxValues intValue];
int noOfResults = [invoiceArray count] ;
if (noOfResults != 0 )
{   
    if (maxResults > noOfResults)
    {
        noOfResults++;
        rowCount = noOfResults;
    }
}
return noOfResults;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == (rowCount -1))
{
    return 50;
}
return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MasterViewIdentifier"] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    UIView* elementView =  [[UIView alloc] initWithFrame:CGRectMake(5,5,312,480)];
    elementView.tag = 0;
    [cell.contentView addSubview:elementView];
    [elementView release];
}
UIView* elementView  = [cell.contentView viewWithTag:0];
for(UIView* subView in elementView.subviews)
{
    [subView removeFromSuperview];
}

UIImageView* imaeView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 78)];
if(indexPath.row == (rowCount-1))
{
    elementView.backgroundColor = [UIColor colorWithRed:0.92578125 green:0.92578125 blue:0.92578125 alpha:1];
}
else
{
    imaeView.image=[UIImage imageNamed:@"estimatecellbg.png" ];
}
[elementView addSubview:imaeView];
[imaeView release];
    return cell;
  }

任何人的帮助将不胜感激。

谢谢你, Monish。

1 个答案:

答案 0 :(得分:2)

的内容
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == (rowCount -1) && moreResults)
    {
        return 50;
    }
    return 80;
}