我试图删除核心数据中的一个对象,当你按下滑动并按删除。问题是它删除了表格单元格,但是当我返回时,再次删除的单元格又回来了。我想这是因为我只删除了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]; }
}