我有一个UITableView
称为症状表......并且当在可补救表UISwitch
中打开时有可补救我在症状表视图单元上显示一个UIImage
以突出显示UISwitch
该单元格的打开。当我在第一个症状的可补救中打开时,我正在显示UISwitch
但单元格正在被重复使用,并且图像也显示在其他症状表视图单元格中。谁能帮我解决这个问题?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==symptomsTableView)
{
PPsymptomTableCell *cell;
static NSString *cellIdentifier=@"cellIdentifier";
cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
cell=[[PPsymptomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
int symptomIDSelected;
symptomIDSelected = [[[mainsymptArray objectAtIndex:indexPath.row]objectForKey:@"SymptID"]intValue];
NSLog(@"%d",[[activeNotificationDictionary objectForKey:[NSNumber numberWithInt:symptomIDSelected]]intValue]);
for (int i = 0; i<activeNotificationDictionary.count; i++)
{
if([[activeNotificationDictionary objectForKey:[NSNumber numberWithInt:symptomIDSelected]]intValue] == symptomIDSelected)
{
cell.selectedCellImageDisplay.hidden=NO;
}
else
{
cell.selectedCellImageDisplay.hidden=YES;
}
}
NSLog(@"end of symptoms cell for row");
if (searching==YES)
{
cell.symptomCellLabel.text=[[searchSymptomsArray objectAtIndex:indexPath.row] objectForKey:@"SymptName"];
cell.backgroundColor=[UIColor clearColor];
return cell;
}
else
{
cell.backgroundColor=[UIColor clearColor];
NSArray *sectionArray=[mainIndexDictionary objectForKey:[allKeysArray objectAtIndex:indexPath.section]];
cell.symptomCellLabel.text=[[sectionArray objectAtIndex:indexPath.row] objectForKey:@"SymptIndexName"];
return cell;
}
}
这里的 activenotification 字典是一个NSMutableDictionary
包含特定症状 ID 的补救 ID 值的地方。这是症状表的UITableViewCell
习惯
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
self.symptomCellImageView.contentMode=UIViewContentModeScaleToFill;
selectedCellImageDisplay = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"selectedSymptomImage.png"]];
selectedCellImageDisplay.frame = CGRectMake(230.0, 8.0, 30.0, 30.0);
selectedCellImageDisplay.hidden=YES;
symptomCellLabel=[[UILabel alloc]initWithFrame:CGRectMake(15.0,0.0 ,280.0,40.0)];
symptomCellLabel.font=[UIFont fontWithName:@"Rockwell" size:17];
symptomCellLabel.textColor=[UIColor blackColor];
symptomCellLabel.backgroundColor=[UIColor clearColor];
[self.contentView addSubview:symptomCellLabel];
[self.contentView addSubview:selectedCellImageDisplay];
// Initialization code
}
return self;
}