UITableViewCell正在重用

时间:2013-02-26 17:16:22

标签: ios objective-c uitableview

我有2个uitableview当我点击一个tableview它进入另一个tableview ...我在第二个tableview中有一个uiswitch,当我打开一个图像应该出现在第一个tableview上,这表示一个开关在第二个特定第一个tableviewcell的tableview。

在cellforroatindexpath中我添加了uiimage,它添加在特定tableview的customcell中。

BOOL selectedIndicationShouldBeVisible = NO;

for (int i = 0; i<activeNotificationDictionary.count; i++)
{
if([[activeNotificationDictionary objectForKey:[NSNumber numberWithInt:symptomIDSelected]]intValue] == symptomIDSelected)
    {
selectedIndicationShouldBeVisible = YES;
    }
}

cell.selectedCellImageDisplay.hidden=!selectedIndicationShouldBeVisible;

在此代码中,我们将知道第二个tableview uiswitch中的哪个tableviewcell处于ON / OFF状态 activeNotificationDictionary包含针对remedidID(第二个tableview)的哪个症状ID(第一个表视图)UISwitch为ON

(void)notificationChangedForSymptom:(int)symptomIDNo withRemedyID:(int)remedyID isSelected:(BOOL)isSelected 
{
    if (isSelected == YES)
    {        
        selectedSymptomID = symptomIDNo;
        selectedRemedyID = remedyID;

        [self scheduleNotification:remedyID];

        NSLog(@"dictionary %@",activeNotificationDictionary);

        if ([activeNotificationDictionary objectForKey:[NSNumber numberWithInt:symptomIDNo]] != nil)
       {
           UIAlertView *selectedNotification = [[UIAlertView alloc]initWithTitle:@"Reminder" message:@"Would you like to change the notification" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];

           selectedNotification.delegate = self;
           NSLog(@" selected remedyID for symptom %@", activeNotificationDictionary);

           [selectedNotification show];

           NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

           NSData *data = [NSKeyedArchiver archivedDataWithRootObject:activeNotificationDictionary];

           [defaults setObject:data forKey:@"dictKey"];
           [defaults synchronize];

       }

       else
       {


           [activeNotificationDictionary setObject:[NSNumber numberWithInt:remedyID] forKey:[NSNumber numberWithInt:symptomIDNo]];

       }
        NSLog(@"dictionary %@",activeNotificationDictionary);


    }

    else

      {
          [activeNotificationDictionary removeObjectForKey:[NSNumber numberWithInt:symptomIDNo]];
          [self cancelNotification:remedyID];
      }

}

我的问题是当我执行时,如果我打开,图像将被添加到第一个tableview中的其他tableviewcell而不是一个单元格

0 个答案:

没有答案