我試圖刪除核心數據中的一個對象,當你按下滑動並按刪除。問題是它刪除了表格單元格,但是當我返回時,再次刪除的單元格又回來了。我想這是因爲我只刪除了NSMUtableArray(設備)中的對象,並沒有刪除核心數據對象。我怎樣才能做到這一點?刪除核心數據對象和表格
其中對象將被保存的saveTap:
-(void)saveTap:(id)sender{
Entity *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Entity" inManagedObjectContext:_managedObjectContext];
[newManagedObject setValue:self.textfield.text forKey:@"playlistName"];
[newManagedObject setValue:[NSNumber numberWithInt:selectedRowValue] forKey:@"idnumber"];
// Save the context.
NSError *error = nil;
if (![_managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self fetchDevices];
NSLog(@"COUNT %d", [devices count]);
}
和commiteditingstyle方法
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.devices removeObjectAtIndex:indexPath.row];
[tableViewData reloadData]; }
}