我正在使用一个视图控制器,用户应该删除位于谷歌驱动器中的电子表格中的一行表格。
用户成功登录后,将显示一个表视图,用户可以通过在适当的单元格上向左滑动来删除该行。下面的代码显示了删除过程。当我触发该过程时,会显示以下错误:
“无效请求[0] .deleteRange:无网格ID:0”
//Delete Function TableView - Access by swiping left.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
//1 - Delete Row From Index
let toDelete = GTLRSheets_DeleteRangeRequest.init()
toDelete.range?.sheetId = 317088521
toDelete.range?.startRowIndex = 6
toDelete.range?.endRowIndex = 6
toDelete.range?.startColumnIndex = 0
toDelete.range?.endColumnIndex = 3
toDelete.shiftDimension = "ROWS"
let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
let request = GTLRSheets_Request.init()
request.deleteRange = toDelete
batchUpdate.requests = [request]
let deleteQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetID)
service.executeQuery(deleteQuery, delegate: self, didFinish: #selector(deleteFromIndexWithTicket(ticket:finishedWithObject:error:)))
}
func deleteFromIndexWithTicket(ticket: GTLRServiceTicket, finishedWithObject result : GTLRSheets_BatchGetValuesResponse , error : NSError?) {
if let error = error {
print(error.localizedDescription)
return
}
print("Deleted from index")
}
答案 0 :(得分:0)
我的不好......我没有初始化GridRange。以下是工作代码。
//1 - Delete Row From Index
let toDelete = GTLRSheets_DeleteRangeRequest.init()
let gridRange = GTLRSheets_GridRange.init()
toDelete.range = gridRange
gridRange.sheetId = indexID as NSNumber
gridRange.startRowIndex = lengthTrainingDatabase - indexPath.row as NSNumber
gridRange.endRowIndex = lengthTrainingDatabase - indexPath.row + 1 as NSNumber
toDelete.shiftDimension = kGTLRSheets_DeleteRangeRequest_ShiftDimension_Rows