Jignesh Fadadu
Jignesh Fadadu

Reputation: 409

Multiple checkbox selection values to be displayed into the different cells of TableView

I have to select dynamically (random) check boxes which will be displayed into the previous list page below the cell values & for all cells it must be different as per the selection of those check boxes for the particular selected cells & when i will select particular cell from the list the listed check boxes should be selected in the list of the check boxes.

Is this possible? If possible then please tell me how.

Upvotes: 3

Views: 1053

Answers (2)

Jean-Luc Godard
Jean-Luc Godard

Reputation: 1883

This is what you want jignesh...

http://cocoawithlove.com/2009/01/multiple-row-selection-and-editing-in.html

best of luck

Upvotes: 2

Ishu
Ishu

Reputation: 12787

Yes it is possible you need to make an array of indexes and store indexes of the rows in which checkboxes are present.

What you need when you are making cells and add checkbox buttons then add index.row as its titleLabel.text. see this

UIButton *btn=(UIButton *)[cell viewWithTag:2];
        if([self.indexArray containsObject:[NSString stringWithFormat:@"%i",indexPath.row]])
        {
          [btn setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
        }
        else 
         [btn setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(changeButtonImage:) forControlEvents:UIControlEventTouchUpInside];
        btn.titleLabel.text=[NSString stringWithFormat:@"%i",indexPath.row];

This code make your check box buttons and add its row no. with the button now you can access that button by this code.Also here i use an array index array which having indexes for checked rows.

Now see this function

-(void)changeButtonImage:(UIButton *)sender
{
    if([self.indexArray containsObject:sender.titleLabel.text])
    {

        [sender setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
        [self.indexArray removeObject:sender.titleLabel.text];  
    }
    else 
    {

        [sender setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
        [self.indexArray addObject:sender.titleLabel.text];
    }
    //other stuff
}

here simply add index and change button image to checked when indexarray not having that index otherwise remove that and set image unchecked.

Use this info with you logic and presence of mind.

Note:This is not exact answer but it shows a concept which you can use according to your situation.

It may be help full for you.

Upvotes: 2

Related Questions