我的图像视图在表格视图中表现不正常?

时间:2013-01-03 14:27:30

标签: iphone ios ipad

我以下面的方式加载表格视图。如果满足条件,我需要在cell.imageview上方添加特定图像。图像也有不同的尺寸。以下是我的代码可以任何人指出我在哪里出错。

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
if(array==nil||[array count]==0)
{

}
else
{
    NSMutableDictionary *dicttable=[array objectAtIndex:indexPath.row];
    NSString *head=[dicttable objectForKey:@"name"];
    NSString *type=[dicttable objectForKey:@"type"];

    NSString *imgUrl = [dicttable objectForKey:@"image"];;
    if(imgUrl!=nil)
    {
        if(![[ImageCache sharedImageCache] hasImageWithKey:imgUrl])
        { 
            cell.imageView.image = [UIImage imageNamed:@"noimage_icon.png"];
            NSArray *myArray = [NSArray arrayWithObjects:cell.imageView,imgUrl,@"noimage_icon.png",[NSNumber numberWithBool:NO],nil];
            AppDelegate *appDelegate = (AppDelegate  *)[[UIApplication sharedApplication] delegate];
            [appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];
            cell.imageView.frame=CGRectMake(0,0,48,48);
            cell.imageView.bounds=CGRectMake(0,0,48,48);
            [cell.imageView setClipsToBounds:NO];
        }
        else
        {
            cell.imageView.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:imgUrl];
            cell.imageView.frame=CGRectMake(0,0,48,48);
            cell.imageView.bounds=CGRectMake(0,0,48,48);
            [cell.imageView setClipsToBounds:NO];
        }
    }
    else
    {
        cell.imageView.image = [UIImage imageNamed:@"noimage_icon.png"];
    }
    if([type isEqualToString:@"YES"])
    {
        UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bluel.png"]];
        [cell setBackgroundView:img];
        [img release];

        cell.textLabel.text = head;
        cell.textLabel.backgroundColor = [UIColor clearColor];

        cell.detailTextLabel.textColor=[UIColor grayColor];
        cell.detailTextLabel.text = subtitle1;
        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    }
    else
    {
        UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"wnew1.png"]];
        [cell setBackgroundView:img];
        [img release];
        cell.textLabel.text = head;
        cell.textLabel.backgroundColor = [UIColor clearColor];
        [cell.imageView addsubview:spclimage]

        cell.textLabel.text = head;
        cell.textLabel.backgroundColor = [UIColor clearColor];

        cell.detailTextLabel.textColor=[UIColor grayColor];
        cell.detailTextLabel.text = subtitle1;
        cell.detailTextLabel.backgroundColor = [UIColor clearColor];            
    }
}
return cell;

此问题仅出在特殊图像添加的最后一行。不在所有行中。在tableview重新加载的过程中,图像视图大小也是不同的吗?

1 个答案:

答案 0 :(得分:1)

有几点想法:

  1. updateImageViewInBackground似乎很可疑,因为名称表明您正在更新图片视图,但未指定要更新的单元格。

  2. 我也看到你在做addSubview:spclimage。显然,如果spclimage位于另一个单元格上,只要执行addSubview,它就会在添加到当前单元格之前从之前的位置删除。事实上,只是将图像添加为现有图像视图的子视图这一概念很奇怪。

  3. 如果您的缓存还没有图片,我会看到您使用noimage_icon.png初始化图片的位置,但我看不到您实际更新图片视图的位置。你说updateImageViewInBackground是“然后更新图像”。您的意思是为此image为此imageView设置cell的{​​{1}}属性吗?或者更新indexPath?如果是这样,那就有问题了。

  4. 典型的模式(使用spclimage)将是:

    GCD
相关问题