Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- { [tableView beginUpdates];
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- [self.alphabets removeObjectAtIndex:indexPath.row];
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
- }
- if (editingStyle == UITableViewCellEditingStyleInsert) {
- [self.alphabets insertObject:[self.alphabets objectAtIndex:indexPath.row] atIndex:[self.alphabets count]-1];
- NSIndexPath * path1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
- NSArray * index = [NSArray arrayWithObjects:path1, nil];
- [self.tableView insertRowsAtIndexPaths:index withRowAnimation:UITableViewRowAnimationAutomatic];
- }
- [tableView endUpdates];
- NSLog(@"%@",self.alphabets);
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView beginUpdates];
- if (editingStyle == UITableViewCellEditingStyleInsert) {
- [self.alphabets insertObject:[self.alphabets objectAtIndex:indexPath.row] atIndex:[ self.alphabets count]-1];
- NSIndexPath * path1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
- NSIndexPath * path2 = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
- NSArray * index = [NSArray arrayWithObjects:path1,path2, nil];
- [self.tableView insertRowsAtIndexPaths:index withRowAnimation:UITableViewRowAnimationAutomatic];
- }
- [tableView endUpdates];
- NSLog(@"%@",self.alphabets);
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (editingStyle == UITableViewCellEditingStyleInsert) {
- UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Inserting a new row" message:@"Enter text below to add it to table view" preferredStyle:UIAlertControllerStyleAlert];
- [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- }];
- UIAlertAction * ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- NSArray * tfArray = alert.textFields;
- UITextField * tf = [tfArray objectAtIndex:0];
- self.userInput = tf.text;
- NSLog(@"%@",self.userInput);
- [self.alphabets insertObject:self.userInput atIndex:indexPath.row];
- [tableView reloadData];
- }];
- [alert addAction:ok];
- [self presentViewController:alert animated:NO completion:nil];
- }
- NSLog(@"%@",self.alphabets);
- }
Add Comment
Please, Sign In to add comment