如果单击复选框,则行中的其他复选框应隐藏在使用目标c的tableview中

时间:2017-05-08 11:30:52

标签: ios objective-c iphone

    - (IBAction) creatorAction:(id)sender
{
    button=(UIButton *)sender;
    NSInteger tag = [button tag];
    NSLog(@" creator :%ld",(long)tag);
    button.selected = !button.selected;
    if(button.selected)
    {
        button.selected = TRUE;
        NSLog(@" creator status :%d",button.selected);
        NSObject *creatorData = [totalString objectAtIndex:tag];
        NSLog(@"creator data added: %@",creatorData);
        Creator[tag]=@"True";
        if((Creator[tag]=@"True"))
        {
            Modifier[tag]=@"True";
            [modifierButton setHidden:YES];
            Approver[tag]=@"True";
            [approverButton setHidden:YES];
        }
    [cs addObject:creatorData];
    }

    else
    {
        button.selected = FALSE;
        Creator[tag]=@"False";
        if((Creator[tag]=@"False"))
        {
            Modifier[tag]=@"False";
            [modifierButton setHidden:NO];
            Approver[tag]=@"False";
            [approverButton setHidden:NO];
        }

        NSLog(@" creator status :%d",button.selected);
        NSObject *creatorData = [totalString objectAtIndex:tag];
        NSLog(@"approver  data removed: %@",creatorData);
        // [createrArray removeObject:creatorArray];
        [cs removeObject:creatorData];
    }
       NSLog(@"Final creater array: %@",Creator);
       NSLog(@"Final cs array: %@",cs);
     //modifierButton.enabled = NO;
}

- (IBAction) modifierAction:(id)sender
{
    button1=(UIButton *)sender;
    NSInteger tag = [button1 tag];
    NSLog(@" modifier :%ld",(long)tag);
  //NSLog(@"%d",AddAdminViewController.selectedId));
    button1.selected = !button1.selected;
    if(button1.selected)
    {
        button1.selected = TRUE;
        NSLog(@" modifier status :%d",button1.selected);
        NSObject *modifierData = [totalString objectAtIndex:tag];
        NSLog(@"modifier data added: %@",modifierData);
        Modifier[tag]=@"True";
     // [modifierArray addObject:modifierArray];
        [ms addObject:modifierData];
    }
    else
    {
        button1.selected = FALSE;
        Modifier[tag]=@"False";
        NSLog(@" modifier status :%d",button1.selected);
        NSObject *modifierData = [totalString objectAtIndex:tag];
        NSLog(@"approver  data removed: %@",modifierData);
     // [modifierArray removeObject:modifierArray];
        [ms removeObject:modifierData];
    }
    NSLog(@"Final Modifier array: %@",Modifier);
    NSLog(@"Final ms array: %@",ms);
}

- (IBAction) approverAction:(id)sender
{
    button2=(UIButton *)sender;
    NSInteger tag = [button2 tag];
    NSLog(@" approver :%ld",(long)tag);

  //NSLog(@"%d",AddAdminViewController.selectedId));
    button2.selected = !button2.selected;
    if(button2.selected)
    {
        button2.selected = TRUE;
        NSLog(@" approver status :%d",button2.selected);
        NSObject *approverData = [totalString objectAtIndex:tag];
        NSLog(@"approver data added: %@",approverData);
        Approver[tag]=@"True";
        [as addObject:approverData];
    }
    else
    {
        button2.selected = FALSE;
        Approver[tag]=@"False";
        NSLog(@" approver status :%d",button2.selected);
        NSObject *approverData = [totalString objectAtIndex:tag];
        NSLog(@"approver  data removed: %@",approverData);
     // [approverArray removeObject:approverData];
        [as removeObject:approverData];
    }
    NSLog(@"Final Approver array: %@",Approver);
    NSLog(@"Final as array: %@",as);
}


-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  NSLog(@"Hello %lu",(unsigned long)[totalString count]);
  return [totalString count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"cell";
 // NSLog(@"%ld",(long)indexPath.row);
    UIImage *image1 = [UIImage imageNamed:@"images.png"];
    UIImage *image2 = [UIImage imageNamed:@"Image-1.png"];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        }

    creatorButton = [[UIButton alloc] initWithFrame:CGRectMake(250.0, 20.0, 20.0, 20.0)];
    [creatorButton addTarget:self action:@selector(creatorAction:) forControlEvents:UIControlEventTouchUpInside];
    [creatorButton setImage:image1 forState:UIControlStateNormal];
    [creatorButton setImage:image2 forState:UIControlStateSelected];
    creatorButton.tag = indexPath.row;
    creatorButton.backgroundColor = [UIColor clearColor];
    creatorButton.selected = NO;
    [cell addSubview:creatorButton];
    button.selected = FALSE;
    NSLog(@"creator tag:%ld",(long)creatorButton.tag);
    NSLog(@"Index row value %ld",(long)indexPath.row);

    modifierButton = [[UIButton alloc] initWithFrame:CGRectMake(310.0, 20.0, 20.0, 20.0)];
    [modifierButton addTarget:self action:@selector(modifierAction:) forControlEvents:UIControlEventTouchUpInside];
    [modifierButton setImage:image1 forState:UIControlStateNormal];
    [modifierButton setImage:image2 forState:UIControlStateSelected];
    modifierButton.tag =indexPath.row;
    modifierButton.backgroundColor = [UIColor clearColor];
    modifierButton.selected = NO;
    [cell addSubview:modifierButton];
    button1.selected = FALSE;
    NSLog(@" Modifier tag :%ld",(long)modifierButton.tag);

    approverButton = [[UIButton alloc] initWithFrame:CGRectMake(375.0, 20.0, 20.0, 20.0)];
    [approverButton addTarget:self action:@selector(approverAction:) forControlEvents:UIControlEventTouchUpInside];
    [approverButton setImage:image1 forState:UIControlStateNormal];
    [approverButton setImage:image2 forState:UIControlStateSelected];
    approverButton.tag = indexPath.row;
    approverButton.backgroundColor = [UIColor clearColor];
    approverButton.selected = NO;
    [cell addSubview:approverButton];
    button2.selected = FALSE;
    NSLog(@" Approver tag :%ld",(long)approverButton.tag);

    UIImage *profileImages = [UIImage imageNamed:@"image2.png"];
    cell.imageView.image = profileImages;
    cell.textLabel.text = [totalString objectAtIndex:indexPath.row];
    return cell;
}

上面是代码,如果单击一个复选框,则同一行中的其他复选框应隐藏在具有多个相同行的tableview中。当我从行中单击第一个复选框时,它隐藏了最后一个对象复选框。我在一行中添加了三个按钮,根据行复制相同的按钮。该如何做?Attached image here

0 个答案:

没有答案