redribben

reload cell when switch triggered

Feb 3rd, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.     ...
  3.     ...
  4.     [cell.cellSwitch addTarget:self action:@selector(switchUD:) forControlEvents:UIControlEventValueChanged];
  5.     [cell.cellSwitch setTag:indexPath.row];
  6.     ...
  7.     ...
  8. return cell
  9. }
  10.  
  11.  
  12.  
  13. -(void)switchUD:(id)sender {
  14.     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
  15.     NSArray* rowsToReload = [NSArray arrayWithObjects:indexPath, nil];
  16.     [self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  17. }
Advertisement
Add Comment
Please, Sign In to add comment