Пиша код, който получава рецепти под формата на JSON от сървър и го представя в UItable.
NSURL *url = [NSURL URLWithString:@"http://domain.com/recipes"];
[config setHTTPAdditionalHeaders:@{@"Authorization":@" Token token=\"3f71235466468b7f7\""}];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
[[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
recipes= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
[self.tableView reloadData];
}
] resume];
Този сървър е написан на Ruby. Сега искам да напиша молба за изтриване на рецепта. Ето това е инструкцията на моя сървър. Каза, че трябва да използвам следния curl, за да изтрия рецепти:
Изтриване на рецепти DELETE: /recipes/:id В Curl би било нещо подобно:
curl -H 'Authorization: Token token="0b774d575632b"' -X DELETE http://domain.com/recipes/22
Бих искал да внедря метода за изтриване. Всъщност знаех, че трябва да внедря следния метод.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//how to delete it from server??????
// Remove the row from data model
[recipes removeObjectAtIndex:indexPath.row];
// Request table view to reload
[tableView reloadData];
}
Някой знае ли как мога да внедря метода за изтриване?