0

質問と回答セッション、表の行に複数の回答がある質問など、複数のリストを作成しています。しかし、行を選択するたびに、他の質問の回答も選択され、同じに戻ったときにすべての選択がなくなります。では、これを回避する方法は? 助けてください。私のコードは、

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(val==1)
    {
        checkedArr=[[NSMutableArray alloc] init];
        for (int i = 0; i<17; i++)
        {
            [checkedArr addObject:@"1"];
        }
        NSLog(@"Checked arr size %i",[checkedArr count]);

        return 17;
    }
    else if(val==2)
    {
        checkedArr=[[NSMutableArray alloc] init];
        for (int i = 0; i<13; i++)
        {
            [checkedArr addObject:@"1"];
        }
        return 13;
    }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i",indexPath.row];
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil)
    {
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
    }
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0];

    UIView *selectionColor = [[UIView alloc] init];
    selectionColor.backgroundColor = [UIColor colorWithRed:99/255.0f green:209/255.0f blue:248/255.0f alpha:1.0];
    cell.selectedBackgroundView = selectionColor;

    if([[checkedArr objectAtIndex:indexPath.row] isEqual:@"0"])
    {
        cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tick.png"]];
         [checkedArr addObject:indexPath];
        NSLog(@"checkedArr 0000000");
    }
    else if ([[checkedArr objectAtIndex:indexPath.row] isEqual:@"1"])
    {
        cell.accessoryView.hidden=TRUE;
        //cell.accessoryView=Nil;
        [checkedArr removeObject:indexPath];

        NSLog(@"checkedArr 111111");
    }


    cell.textLabel.frame=CGRectMake(75.0, 50.0, 150.0, 20.0);
    cell.textLabel.text=[listArray objectAtIndex:indexPath.row];
    NSLog(@"Checked arr size %i",[checkedArr count]);

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      cell=[questionTable cellForRowAtIndexPath:indexPath];
 [checkedArr replaceObjectAtIndex:indexPath.row withObject:@"0"];
    if([[checkedArr objectAtIndex:indexPath.row] isEqual:@"0"])
    {
       cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tick.png"]];
        [checkedArr addObject:indexPath];
        NSLog(@"checkedArr 0000000");

    }
    else if ([[checkedArr objectAtIndex:indexPath.row] isEqual:@"1"])
    {
        cell.accessoryView=nil;
        [checkedArr removeObject:indexPath];
        NSLog(@"checkedArr 111111");
    }
  [questionTable deselectRowAtIndexPath:indexPath animated:YES];
   //[self.questionTable reloadData];
    NSLog(@"Val is %i",val);
    NSLog(@"selected is %@",[listArray objectAtIndex:indexPath.row]);
//    NSLog(@"Checked arr descripton %@",[checkedArr description]);
}


-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.accessoryView = nil;
}
4

0 に答える 0