title: How do you select uitableview rows programmatically
body: <p>I am trying to achive a email like select all functionality in uitableview where on same button tap user can checkmark or remove all checkmark and additionally user can also select/deselect rows(on didSelectRowAtIndexPath). I tried to do but its not working properly,  here is my code.</p>
  
  <pre><code>- (IBAction)selectAll:(id)sender
  {
      if(myBoolean)
      {
          for (NSInteger s = 0; s &lt; self.iTable.numberOfSections; s++)
          {
              for (NSInteger r = 0; r &lt; [self.iTable numberOfRowsInSection:s]; r++)
              {
                  [[self.iTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]] setAccessoryType:UITableViewCellAccessoryNone];
              }
          }
  
          myBoolean = NO;
  
          [_selectUnselectButton setTitle:@"Select all Friends" forState:UIControlStateNormal];
      }
      else
      {
          for (NSInteger s = 0; s &lt; self.iTable.numberOfSections; s++)
          {
              for (NSInteger r = 0; r &lt; [self.iTable numberOfRowsInSection:s]; r++)
              {
                  [[self.iTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]] setAccessoryType:UITableViewCellAccessoryCheckmark];
                  NSLog(@"%d-%d",s,r);
              }
          }
  
          myBoolean = YES;
  
          [_selectUnselectButton setTitle:@"Unselect all Friends" forState:UIControlStateNormal];
      }
  }
  
  
  -(void)tableView:(UITableView *)tableView_ didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      UITableViewCell *cell = [tableView_ cellForRowAtIndexPath:indexPath];
  
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  
      if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
      {
          cell.accessoryType = UITableViewCellAccessoryNone;
      }
      else
      {
          cell.accessoryType = UITableViewCellAccessoryCheckmark;
      }
  }
  </code></pre>