试图在单元格内加载图像。我能够在单元格内加载图像,但是当上下滚动 tableView 时,图像也会随机出现在其他不同的单元格内......
这是一些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView_ dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.textColor = [UIColor whiteColor];
}
if (indexPath.section == ONE_SECTION) {
switch(indexPath.row) {
case 0:{
//some code
}
break;
case 2:{
//some code
}
break;
case 3:{
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(256,0,43,43)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:imageView];
imageView.layer.cornerRadius = 10.0;
//imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.layer.masksToBounds = YES;
imageView.image = [UIImage imageNamed:@"imageName.png"];}
break;
default:
break;
}
}
if (indexPath.section == TWO_SECTION) {
//some code
}
if (indexPath.section == THREE_SECTION) {
//some code
}
return cell;
}
谢谢你