- (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
Asked
Active
Viewed 46 times
-1

Uma Madhavi
- 4,851
- 5
- 38
- 73
-
Check sample one it may be useful to you http://stackoverflow.com/a/18962773/5184217 – Rajesh Dharani Mar 31 '17 at 10:05
-
in this link they are only removing data from an array not from api.. – Dinesh TBX Mar 31 '17 at 10:29
-
So deleting the data from api Then you can reload tableview data – Rajesh Dharani Mar 31 '17 at 10:33
1 Answers
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
-
So what should i do that my data is remove from local Array as well as server. – Dinesh TBX Mar 31 '17 at 08:54