我的UITableView
正在從數組中提取數據。此數組中的項目有一個名爲IsSelected的屬性。我正在嘗試將UIImageView
放入單元格contentView
中,用於選擇每個項目。UIImageView添加到單元格contentView在滾動UITableView時隨機顯示
然而,當重複使用單元格時,UITableView
會導致我的圖像在不應該使用的單元格上重用。我無法弄清楚我的生活,我應該如何改變它。我附上了一個顯示問題的屏幕快照。如果我繼續和滾動上下圖像去所有的地方:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SchoolCellIdentifer = @"SchoolCellIdentifier";
SchoolInfoItem *item = [self.schoolsArray objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SchoolCellIdentifer];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SchoolCellIdentifer];
cell.contentView.backgroundColor = [BVColors WebDarkBlue];
}
cell.textLabel.text = item.Name;
if ([item.selected isEqualToString:@"1"])
{
cell.contentView.backgroundColor = [BVColors WebBlue];
UIImageView *selectedItemCheckMarkIcon = [[UIImageView alloc] initWithFrame:CGRectMake(300, 13, 17, 17.5)];
[selectedItemCheckMarkIcon setImage:[UIImage imageNamed:@"check-mark.png"]];
[cell.contentView addSubview:selectedItemCheckMarkIcon];
}
else
{
cell.contentView.backgroundColor = [BVColors WebDarkBlue];
}
return cell;
}
謝謝你做到了! – Flea
非常歡迎:) –