我有一個可用視圖,其中包含人員列表。有些記錄有圖像,有些記錄沒有。如果我向下滾動列表,它看起來是正確的,但如果我向後滾動,那麼另一個人的圖像開始顯示在其他人的細胞行上,圖像不應該是。這是我的代碼cellForRowAtIndexPathUITableView imageView顯示圖像滾動後圖像不應該在哪裏
// START CELL LABELLING FOR TABLE VIEW LIST //
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Person *person = [arrayOfPersons objectAtIndex:indexPath.row];
NSString *personPhoto = person.personPhoto;
NSString* imgPath = [docPath stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@", personPhoto] ];
if ([[NSFileManager defaultManager] fileExistsAtPath:imgPath]){
NSLog(@"FILE EXISTS");
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 0, 67, 67)];
imageView.image = [UIImage imageWithContentsOfFile:imgPath];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:imageView];
}else{
NSLog(@"Does Not Exist");
}
cell.textLabel.text = person.personName;
return cell;
imageView = nil;
personPhoto = @"";
imgPath = @"";
}
// END CELL LABELLING FOR TABLE VIEW LIST //
可能你需要做[cell.contentView.view removeFromSuperview];之前添加一個新的地方。 – kabarga 2014-10-03 12:22:55