2011-01-30 46 views
0

我正在创建一个应用程序,其中有许多表格单元格(> 300)。我已经成功实现了展开和折叠tableview单元格。展开时,显示的是从web服务中获取的图像,单击展开的单元格时,单元格会再次折叠,如果单击了另一个单元格,则先前单元格折叠并且当前单元格展开。现在的问题是,如果用户使用单元格展开表格滚动tableview时效果不错,但是当他返回 时,图像会丢失,并且功能也有一些问题(表格会将该单元格折叠)。滚动后会丢失Expanded TableView中的图像

此外,如果用户不断向下滚动表格,他可以在collapased单元格中看到该图像(这看起来非常糟糕),我认为它是因为dequeueReusableCellWithIdentifier正在获取已扩展的单元格。 PS:每个图像都是基于单元格值而不同,但它是在不同的调用中获取的(不是一起调用,即获取300张图像,我可以调用300次独立调用)。

回答

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UIImageView * imageView; 
    UILabel  * nameLabel; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:CellIdentifier] autorelease]; 

     nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(45.0, 5.0, 245.0, 34.0)]; 
     nameLabel.font = [UIFont fontWithName:CELL_FONT size:CELL_FONT_SIZE]; 
     nameLabel.tag = 2; 
     nameLabel.backgroundColor = [UIColor clearColor]; 
     [cell.contentView addSubview:nameLabel]; 
     [nameLabel release]; 

     imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 30.0, 30.0)]; 
     imageView.tag = 1; 
     imageView.contentMode = UIViewContentModeScaleAspectFit; 
     [cell.contentView addSubview:imageView]; 
     [imageView release]; 
    } 
    else { 
     imageView = (id)[cell.contentView viewWithTag:1]; 
     nameLabel = (id)[cell.contentView viewWithTag:2]; 
    } 

    return cell; 
} 
相关问题