-1
     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

           return result.count;

        }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

       static NSString *CellIdentifier = @"cell";

       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


       if (cell) {


           name = (UILabel *)[cell viewWithTag:10];
           name.text = [result objectAtIndex : indexPath.row];
       }

       else{

           name.tag=indexPath.row;
       }

       return cell;


    }


    - (IBAction)butn:(id)sender {


       [myTbl setEditing:YES animated:YES];

    }
    - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {

       if (self.tbl.editing)
       {
           return UITableViewCellEditingStyleDelete;
       }

       return UITableViewCellEditingStyleNone;
    }

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath    

       if (editingStyle == UITableViewCellEditingStyleDelete) {

           [result removeObjectAtIndex:indexPath.row];
           [self myMethod];//in this method i'm deleting the data from api also
           [tableView reloadData];

       }

    }



    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
       return YES;
    }



  -(void)myMethod{


        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.remove.php"]];
        NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:data];


        NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration
defaultSessionConfiguration]];
        [[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable
 response, NSError * _Nullable error) {
            NSDictionary *JSON= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers
 error:nil];

            NSArray *alertArray = [JSON objectForKey:@"removebookmark"];



      for (NSDictionary *alert in alertArray )

          {

                if ([[alert objectForKey:@"status"] isEqualToString:@"remove"])


                {
                                nslog(@"removebookmark");
                                [spinner stopAnimating];

                }

            }



        }]resume];


     }

@end
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73

1 Answers1

0

I can see that you are removing object from your local array, and not updating your server about the record you have removed.

Now you are requesting the list of removed record(by myMethod function), obviously that record will not be in your web list.

So that record will be visible after reloading your list and as you have decrements total record by one so you wont be able to see last record.

Also don't reload full table, just reload rows and sections as required.

Ashwin Kanjariya
  • 1,019
  • 2
  • 10
  • 22