Guest User

Untitled

a guest
Jan 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  2. { [tableView beginUpdates];
  3. if (editingStyle == UITableViewCellEditingStyleDelete) {
  4. [self.alphabets removeObjectAtIndex:indexPath.row];
  5. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
  6. }
  7. if (editingStyle == UITableViewCellEditingStyleInsert) {
  8.  
  9. [self.alphabets insertObject:[self.alphabets objectAtIndex:indexPath.row] atIndex:[self.alphabets count]-1];
  10.  
  11. NSIndexPath * path1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
  12.  
  13. NSArray * index = [NSArray arrayWithObjects:path1, nil];
  14.  
  15. [self.tableView insertRowsAtIndexPaths:index withRowAnimation:UITableViewRowAnimationAutomatic];
  16. }
  17. [tableView endUpdates];
  18. NSLog(@"%@",self.alphabets);
  19. }
  20.  
  21. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  22. {
  23. [tableView beginUpdates];
  24. if (editingStyle == UITableViewCellEditingStyleInsert) {
  25.  
  26. [self.alphabets insertObject:[self.alphabets objectAtIndex:indexPath.row] atIndex:[ self.alphabets count]-1];
  27.  
  28. NSIndexPath * path1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
  29. NSIndexPath * path2 = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
  30.  
  31. NSArray * index = [NSArray arrayWithObjects:path1,path2, nil];
  32.  
  33. [self.tableView insertRowsAtIndexPaths:index withRowAnimation:UITableViewRowAnimationAutomatic];
  34. }
  35. [tableView endUpdates];
  36. NSLog(@"%@",self.alphabets);
  37. }
  38.  
  39. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  40. {
  41. if (editingStyle == UITableViewCellEditingStyleInsert) {
  42.  
  43. UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Inserting a new row" message:@"Enter text below to add it to table view" preferredStyle:UIAlertControllerStyleAlert];
  44.  
  45. [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  46. }];
  47.  
  48. UIAlertAction * ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  49. NSArray * tfArray = alert.textFields;
  50. UITextField * tf = [tfArray objectAtIndex:0];
  51. self.userInput = tf.text;
  52. NSLog(@"%@",self.userInput);
  53. [self.alphabets insertObject:self.userInput atIndex:indexPath.row];
  54. [tableView reloadData];
  55. }];
  56.  
  57. [alert addAction:ok];
  58. [self presentViewController:alert animated:NO completion:nil];
  59. }
  60.  
  61. NSLog(@"%@",self.alphabets);
  62. }
Add Comment
Please, Sign In to add comment