我有一个Web服务来删除我的数据库中的记录
http://url.com/delete/recordID
我将如何在tableview单元格上实现滑动以删除以调用此URL。
我知道必须在
中完成- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
}
}
但我不确定如何写它
答案 0 :(得分:1)
我猜你有一些包含数据的数组。我建议你使用AFNetworking框架与服务器进行通信。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
Record *record = self.recordsArray[indexPath.row];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager DELETE:[NSString stringWithFormat:@"http://url.com/delete/%@", record.recordId] parameters:nil success:^(AFHTTPRequestOperation * operation, id responseObject) {
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}