我用 uiimage 创建 uitableview 自定义单元格我只想为偶数行添加一个图像,但它在这里不起作用是代码
UITableViewCell *cell;
UILabel *label = nil;
cell = [tv dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
//label information
}
NSString *text = [items objectAtIndex:[indexPath row]];
UIView *selectionView = [[UIView alloc]initWithFrame:cell.bounds];
[selectionView setBackgroundColor:[UIColor colorWithRed:0 green:1 blue:1 alpha:1]];
cell.selectedBackgroundView = selectionView;
if (indexPath.row % 2==0) {
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(128,5, 32, 32)];
imv.image=[UIImage imageNamed:@"England.png"];
[cell.contentView addSubview:img];
[imv release];
}
else {
// ....
}
return cell;
在第 3 行之后,如果我尝试滚动所有行,所有行都会为所有行拍摄这张图片