UITableview中的第一行,与其他行不同

JAA*_*JAA 3 iphone uitableview

我的UITableView需要在第一行中有一个图像.有什么问题?当用户向下滚动桌面视图时,他向上滚动,在图像上方有其他行的信息!你知道为什么吗?

这是我的代码(我使用的是UITableViewCell)

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row != 0) {
    return 73.0;
}
else {
    return 109.0;
}   
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    if (indexPath.row == 0) {
        [[NSBundle mainBundle] loadNibNamed:@"customcell_3" owner:self options:NULL];
        cell = cellaNib_with_image;
    }
    else {
        [[NSBundle mainBundle] loadNibNamed:@"customcell_2" owner:self options:NULL];
        cell = cellaNib;
    }


}

if (indexPath.row == 0) {
    UIImage *rowBackground;
    UIImage *selectionBackground;
    rowBackground = [UIImage imageNamed:@"image.png"];
    selectionBackground = [UIImage imageNamed:@"image.png"];
    cell.backgroundView = [[[UIImageView alloc] init] autorelease];
    ((UIImageView *)cell.backgroundView).image = rowBackground;
    cell.selectedBackgroundView = [[[UIImageView alloc] init] autorelease];
    ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;

}
else {
        NSString *elemento = [NSString stringWithFormat:@"%@", [array objectAtIndex:indexPath.row]];
    UILabel *testoLabel = (UILabel*)[cell viewWithTag:1];
    testoLabel.text = elemento;
//ecc... here a take the other datas
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Sea*_*Lee 10

滚动单元格时,它们会被重用.

因此,第一个细胞可以重复用于其他细胞,反之亦然.

我会使用两个CellIdentifier,一个用于第一行,第二个用于其余行.

如果indexPath.row == 0,则使用CellID1创建/出列单元格,并配置并返回.

如果indexPath.row> 1,使用CellID2创建/出列,请配置并返回.

如果您想继续使用单个cellID,那么在配置它们之前,先将所有内容设置为nil/reset,以便删除以前的数据.