Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  2. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3. [self.usersTable beginUpdates];
  4. UITableViewCell *cell = (UITableViewCell *)[self.usersTable cellForRowAtIndexPath:indexPath];
  5. NSString *userNameToDelete = cell.textLabel.text;
  6. // Data source
  7. [self.appDict removeObjectForKey:userNameToDelete];
  8. self.arrayOfUserNames = [[NSMutableArray alloc] initWithArray:[self.appDict allKeys]];
  9. [self.appDict writeToFile:self.pathOfAppFile atomically:YES];
  10. // Deleting cell
  11. [self.usersTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  12. [self.usersTable endUpdates];
  13. }
  14. }
  15.  
  16. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  17. if (indexPath.row == [self.arrayOfUserNames count]) {
  18. return NO;
  19. }
  20. else {
  21. return YES;
  22. }
  23.  
  24. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  25. return [self.arrayOfUserNames count] + 1;
  26. }
  27.  
  28. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  29. if (editingStyle == UITableViewCellEditingStyleDelete) {
  30. //delete your user record
  31. }
  32. }
  33.  
  34. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  35. if (editingStyle == UITableViewCellEditingStyleDelete) {
  36.  
  37. NSString *userNameToDelete = [[self arrayOfUserNames] objectAtIndex:indexPath.row];
  38. // Data source
  39. [self.appDict removeObjectForKey:userNameToDelete];
  40. self.arrayOfUserNames = [[NSMutableArray alloc] initWithArray:[self.appDict allKeys]];
  41. [self.appDict writeToFile:self.pathOfAppFile atomically:YES];
  42.  
  43. [tableView reloadData];
  44.  
  45.  
  46. }
  47. }
  48.  
  49. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement