【发布时间】:2016-12-06 04:25:10
【问题描述】:
编辑单元格后,我无法从核心数据持久存储重新加载数据。
我尝试重新加载 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];
}
}
【问题讨论】:
标签: ios uitableview core-data