我有以下方式加載表視圖。如果符合條件,我需要在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的所有時間都不相同。
這就是開玩笑的圖像緩存梅索德其中WE R緩存images.thats all.nothing正在發生的事情更在那裏。 – hacker
@Rob它一個appdelegate方法,我們將圖像存儲到緩存,然後更新圖像。 – hacker
@Rob非常感謝那寶貴的最後評論。如果我需要添加特殊圖像到所有的細胞可以幫助我如何做到這一點? – hacker