0

Can any one please tell a code for unchecking a entire check marks in uitableview using a button click?

fazil
  • 57
  • 1
  • 8

2 Answers2

2

Create an NSMutableArray in your tableView datasource class and in your cellForRowAtIndexPath method, add the checkboxes to the Array. (check for duplicate).

Then on button click, iterate the array and uncheck them.

atastrophic
  • 3,153
  • 3
  • 31
  • 50
  • its only works wen i select a particular cell.i want to uncheck entire table by the button clik.pls help @tGilani – fazil Aug 11 '12 at 09:49
  • the UITableView only loads the required cells in memory and reuses them and those cells are created in cellForRowAtIndexPath. We cannot get reference to checkboxes not yet created. – atastrophic Aug 11 '12 at 10:20
  • Can you show how you are checking marks for selected rows? You can simply add in the indexPaths for which you have selected and show checkmarks in cellForRowAtIndexPath method in cells at those indexpaths only.And at your buttonClick you can remove all the objects from this array.And call cellForRowAtIndexPath method again or reload your table. – AJS Aug 11 '12 at 11:40
  • @AJS can you explain via coding please – fazil Aug 13 '12 at 05:07
1

In didSelectRowAtIndexPath :

if (![myMutableArray containsObject:indexPath]) {
    [myMutableArray addObject:indexPath]; 
}
else{
    [myMutableArray removeObject:indexPath];
}

[sampleTableView reloadData];

And in cellForRowAtIndexPath :

if ([myMutableArray containsObject:indexPath]) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else{
    cell.accessoryType = UITableViewCellAccessoryNone;
}

And when button clicked, in that method remove the objects from this array and reload your tableView:

[myMutableArray removeAllObjects];
[sampleTableView reloadData]; 
AJS
  • 1,403
  • 12
  • 17
  • the above code only select (checkmarked) single row at a time.I want to select multiple rows at a time and want to reset by button also.@AJS – fazil Aug 13 '12 at 06:44
  • @fazil : you have to add each indexpath in this array and when the button is clicked remove all objects i.e. indexpaths from that array.I have mentioned it in my answer. – AJS Aug 20 '12 at 04:02