UITableViewCell被重用

roc*_*cky -2 iphone objective-c uitableview ios

我有一个UITableView叫做症状表...并且在可以补救的时候有可补救UISwitchUIImage在症状表格UISwitch单元格上显示突出显示该单元格为ON.当我在第一症状的可补救措施中打开时,我正在显示,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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这里,activenotification字典是一个NSMutableDictionary包含该特定症状ID的remedyID值的地方.这是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;
}
Run Code Online (Sandbox Code Playgroud)

mat*_*att 7

正在重用该单元格,因为您要求重用它(dequeueReusableCellWithIdentifier:).由于可以重复使用该单元,因此必须明确设置每个单元的所有功能,包括交换机的存在与否及其状态.