Chandan Jee Chandan Jee - 5 months ago 9
Objective-C Question

when if section is selected then all cell is selected .if some cell is selected then not selected section in iOS

how to make expandable selectable section and cell in tableview .when if section is selected then all cell is selected .if some cell is selected then not selected section in iOS
i am new in iPhone app developer so please help me .

Thank you so much! Best regards.

enter image description here

enter image description here

enter image description here

Answer

Follow the steps :

  1. Add a NSMutableArray Globally.
NSMutableArray *TotalListOfCheckmarkArray;
  1. In ViewDidLoad method, Allocate that array. and By default, for all the no of records for list, add the BOOL object "NO" to TotalListOfCheckmarkArray
- (void)viewDidLoad    {

TotalListOfCheckmarkArray =[[NSMutableArray alloc]init];

 for (int i=0; i<[self.lblArray count]; i++) // Number of Rows count 
{
 [self.TotalListOfCheckmarkArray addObject:@"NO"];
}

}
  1. In your Cell for row method use below code for updating the box of check-mark value
if(![[self.TotalListOfCheckmarkArray objectAtIndex:indexPath.row] isEqualToString:@"NO"])
{
    [cell.buttonCheckbox setImage:[UIImage imageNamed:@"check_box_ok.png"] forState:UIControlStateNormal];

}

else
{
    [cell.buttonCheckbox setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
}
  1. Now you want to select all the Rows then use this code for select all rows.
- (IBAction)selectAllButtonClick:(id)sender {

 for (int i=0; i<[self.lblArray count]; i++)
 {

      [TotalListOfCheckmarkArray replaceObjectAtIndex:i withObject:@"YES"];

 }

[self.tblview reloadData];
 }

And whatever logic you are using for selecting a row, instead of that at that place, For that index, Make NO and update in TotalListOfCheckmarkArray array.

I noticed your edit late.

To select the all rows for single section, Just you have write some code to determine by which you will be able to display row as per section, accordingly manage the check-mark array as per your need.

Comments