mercredi 29 juillet 2015

Mark all checkboxes in UITableView with a Button Click

In my UITableView "tableview" I added checkboxes in each row using UITableView default functionality.

- (void)viewDidLoad {
     [tableview setEditing:YES animated:YES];
       }
 -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    return 3;
 }

I can select only Multiple checkboxes.But I want to select all the checkboxes using a button click.I can use didSelectRowAtIndexPath to loop through all the rows and get the contents but the checkboxes stays unchecked.

- (IBAction)selectallbutton:(id)sender {

   NSInteger nRows=[arr count];

    for(int i=0;i<nRows;i++){
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        [self tableView:tableview didSelectRowAtIndexPath:indexPath];


    }
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"%@",[arr objectAtIndex:indexPath.row]);
}

Is it possible to check them all using this approach or should I try another way?




Aucun commentaire:

Enregistrer un commentaire