我在編輯單元格後從核心數據持久存儲中重新加載數據時遇到問題。如何在cellEdit後強制從持久性存儲重新加載核心數據
我試着重新加載tableView本身,但不強制從持久存儲中獲取,我如何強制重新加載?
這是我在重裝嘗試不工作,如果我退出的UIViewController和回去的所有作品,所以我知道持久存儲正確更新
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
if([NWTillHelper isDebug] == 1) {
NSLog(@"TransactionListView:tableView:context = %@", context);
}
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSManagedObject *transactionRow = [self.transactionRowsRows objectAtIndex:indexPath.row];
[transactionRow setValue:[NSNumber numberWithInt:[@"999" intValue]] forKey:@"status"];
[transactionRow setValue:[NSNumber numberWithInt:[@"0" intValue]] forKey:@"qty"];
[transactionRow setValue:[NSDecimalNumber decimalNumberWithString:@"0"] forKey:@"price"];
[transactionRow setValue:[NSDecimalNumber decimalNumberWithString:@"0"] forKey:@"discountPercentage"];
[transactionRow setValue:[NSDecimalNumber decimalNumberWithString:@"0"] forKey:@"discountAmount"];
[transactionRow setValue:[NSDecimalNumber decimalNumberWithString:@"0"] forKey:@"amountTax"];
[transactionRow setValue:[NSDecimalNumber decimalNumberWithString:@"0"] forKey:@"sum"];
NSError *error = nil;
if (![context save:&error]) {
if([NWTillHelper isDebug] == 1) {
NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
return;
}
}
[self.transactionListViewTbl reloadData];
}
}
我有一個託管的對象上下文在每個方法,但在同一個方法,我只有一個,它可以在方法之間衝突嗎?如果是這樣的話,我怎樣才能製造一個貫穿所有方法的堅持? –
謝謝,我有兩個上下文競爭我是一個複製和粘貼錯誤,許多深夜編碼我認爲,欣賞這個頭。 –