Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Can';不保存核心数据_Ios_Objective C_Core Data_Tableview_Simperium - Fatal编程技术网

Ios Can';不保存核心数据

Ios Can';不保存核心数据,ios,objective-c,core-data,tableview,simperium,Ios,Objective C,Core Data,Tableview,Simperium,我尝试使用NSFetchedResultsController和不同的部分在tableview中保存核心数据 添加数据时,出现以下错误: CoreData:错误:严重的应用程序错误。异常被捕获 在核心数据更改处理期间。这通常是一个内部错误 NSManagedObjectContextObjectsIDChangeNotification的观察者* -[\uu NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从具有userInfo

我尝试使用NSFetchedResultsController和不同的部分在tableview中保存核心数据

添加数据时,出现以下错误:

CoreData:错误:严重的应用程序错误。异常被捕获 在核心数据更改处理期间。这通常是一个内部错误 NSManagedObjectContextObjectsIDChangeNotification的观察者<强>* -[\uu NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从具有userInfo(null)的对象[0]插入nil对象 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[\u NSPlaceholderDictionary initWithObjects:forKeys:count::尝试从中插入nil对象 对象[0]*

第一次抛出调用堆栈:(0x181a05900 0x181073f80 0x1818f41a8 0x1818f4040 0x1000a9068 0x1000aa8d8 0x1835905a8 0x183505080 0x183504f48 0x183495108 0x1819aafc4 0x1819aa7e4 0x1819aa564 0x181a0fde4 0x1818eb0f4 0x1822AD2C 0x18349506c 0x1835098d0 0x18349378c 0x183492240 0x1000aa3a0 0x18672fe50 0x1868b34a4 0x18672fe50 0x18672fdcc 0x186717a88 0x186717bd4 0x18672f6e4 0x18672f314 0x186727e30 0x1866f84cc 0x1866f6794 0x1819bcefc 0x1819bc990 0x1819ba690 0x1818e9680 0x182df8088 0x186760d90 0x10004c23c 0x18148a8b8)libc++abi.dylib:以未捕获终止 NSException类型的异常`

我的代码:

MyDetailData* MyDetail = [NSEntityDescription insertNewObjectForEntityForName:@"MyDetailData" inManagedObjectContext:self._privateObjectContext];
[MyDetail setKategorie: NSLocalizedString(@"Test", nil)];
NSError *error = nil;
if (![MyDetail.managedObjectContext save:&error]) {
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
在iOS6下,所有的代码都很好

这是我的NSFetchedResultsController

- (NSFetchedResultsController *)fetchedResultsController2 {

    if (fetchedResultsController2 != nil) {
       return fetchedResultsController2;
    }

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription     entityForName:@"MyDetailData" inManagedObjectContext:_privateObjectContext];
    [request setEntity:entity];

    NSSortDescriptor *KategorieDescriptor = [[NSSortDescriptor alloc] initWithKey:@"kategorie" ascending:YES];
    NSSortDescriptor *oderDescriptor = [[NSSortDescriptor alloc] initWithKey:@"order" ascending:YES];
    NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];

    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:KategorieDescriptor,oderDescriptor,nameDescriptor, nil];
    [request setSortDescriptors:sortDescriptors];


    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:_privateObjectContext sectionNameKeyPath:@"kategorie" cacheName:nil];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController2 = aFetchedResultsController;

    return fetchedResultsController2;

}  
TableView代表

  • NumberOfSectionsTableView
  • 行数部分
  • NSFetchedResultsController didChangeObject-> NSFetchedResultsChangeInsert
  • NSFetchedResultsController didChangeSection-> NSFetchedResultsChangeInsert
调用并包含正确的信息-以下是相关代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[fetchedResultsController2 sections] count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController2 sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

    if (userDrivenDataModelChange) return;

    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
        case NSFetchedResultsChangeDelete:
            [self.tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeUpdate: {
            [self configureCell:[self.tv cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];

            NSString *sectionKeyPath = [controller sectionNameKeyPath];
            if (sectionKeyPath == nil)
                break;

            NSManagedObject *changedObject = [controller objectAtIndexPath:indexPath];
            NSArray *keyParts = [sectionKeyPath componentsSeparatedByString:@"."];
            id currentKeyValue = [changedObject valueForKeyPath:sectionKeyPath];
            for (int i = 0; i < [keyParts count] - 1; i++) {
                NSString *onePart = [keyParts objectAtIndex:i];
                changedObject = [changedObject valueForKey:onePart];
            }
            sectionKeyPath = [keyParts lastObject];
            NSDictionary *committedValues = [changedObject committedValuesForKeys:nil];

            if ([[committedValues valueForKeyPath:sectionKeyPath] isEqual:currentKeyValue])
                break;

            NSUInteger tableSectionCount = [self.tv numberOfSections];
            NSUInteger frcSectionCount = [[controller sections] count];
            if (tableSectionCount != frcSectionCount) {
                // Need to insert a section
                NSArray *mysections = controller.sections;
                NSInteger newSectionLocation = -1;
                for (id oneSection in mysections) {
                    NSString *sectionName = [oneSection name];
                    if ([currentKeyValue isEqual:sectionName]) {
                        newSectionLocation = [mysections indexOfObject:oneSection];
                        break;
                    }
                }
                if (newSectionLocation == -1)
                    return; // uh oh

                if (!((newSectionLocation == 0) && (tableSectionCount == 1) && ([self.tv numberOfRowsInSection:0] == 0)))
                    [self.tv insertSections:[NSIndexSet indexSetWithIndex:newSectionLocation] withRowAnimation:UITableViewRowAnimationFade];
                NSUInteger indices[2] = {newSectionLocation, 0};
                newIndexPath = [[NSIndexPath alloc] initWithIndexes:indices length:2];
            }


        }

        case NSFetchedResultsChangeMove:
            [self.tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                             withRowAnimation:NO];
            [self.tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                             withRowAnimation:NO];
            break;
        default:
            break;
    }
}


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
    switch(type) {

        case NSFetchedResultsChangeInsert:
            if (!((sectionIndex == 0) && ([self.tv numberOfSections] == 1)))
                [self.tv insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
        case NSFetchedResultsChangeDelete:
            if (!((sectionIndex == 0) && ([self.tv numberOfSections] == 1) ))
                [self.tv deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
        case NSFetchedResultsChangeMove:
            break;
        case NSFetchedResultsChangeUpdate: 
            break;
        default:
            break;
    }
}
-(NSInteger)节数表视图:(UITableView*)表视图
{
返回[[fetchedResultsController2节]计数];
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
id sectionInfo=[[fetchedResultsController2 sections]对象索引:节];
返回[sectionInfo numberOfObjects];
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeObject:(id)索引路径中的一个对象:(NSIndexPath*)变更类型的indexPath:(NSFetchedResultsChangeType)类型newIndexPath:(NSIndexPath*)newIndexPath{
if(userdrivendamodelchange)返回;
开关(类型){
案例NSFetchedResultsChangesInsert:
[self.tv insertRowsAtIndexPaths:[NSArray array with object:newindexath]with rownanimation:uitableviewrownanimationfade];
打破
案例NSFetchedResultsChangeDelete:
[self.tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationFade];
打破
案例NSFetchedResultsChangeUpdate:{
[self-configureCell:[self.tv CellForRowatineXpath:indexPath]AtiXpath:indexPath];
NSString*sectionKeyPath=[控制器sectionNameKeyPath];
如果(sectionKeyPath==nil)
打破
NSManagedObject*changedObject=[控制器对象索引路径:indexPath];
NSArray*keyParts=[sectionKeyPath组件由字符串分隔:@.”;
id currentKeyValue=[changedObject valueForKeyPath:sectionKeyPath];
对于(int i=0;i<[关键部件计数]-1;i++){
NSString*onePart=[keyParts objectAtIndex:i];
changedObject=[changedObject valueForKey:onePart];
}
sectionKeyPath=[keyParts lastObject];
NSDictionary*committedValues=[changedObject CommittedValuesOffrkeys:nil];
如果([[committedValues valueForKeyPath:sectionKeyPath]isEqual:currentKeyValue])
打破
NSUInteger tableSectionCount=[self.tv numberOfSections];
NSU整数frcSectionCount=[[controller sections]count];
if(tableSectionCount!=frcSectionCount){
//需要插入一节吗
NSArray*mysections=controller.sections;
NSInteger newSectionLocation=-1;
for(id为mysections中的一个节){
NSString*sectionName=[oneSection name];
if([currentKeyValue isEqual:sectionName]){
newSectionLocation=[mysections indexOfObject:oneSection];
打破
}
}
if(newSectionLocation==-1)
return;//uh-oh
如果(!((newSectionLocation==0)&&(tableSectionCount==1)&([self.tv numberOfRowsInSection:0]==0)))
[self.tv insertSections:[NSIndexSet IndexBethIndex:NewsSectionLocation]带RowAnimation:UITableViewRowAnimationFade];
NSU整数索引[2]={newSectionLocation,0};
newindexath=[[nsindepath alloc]initwithindex:index-length:2];
}
}
案例NSFetchedResultsChangeMove:
[self.tv deleteRowsatindExpath:[NSArray arrayWithObject:indexPath]
WithRow动画:否];
[self.tv insertrowsatindexpath:[NSArray arraywhithobject:newIndexPath]
WithRow动画:否];
打破
违约:
打破
}
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeSection:(id)sectionInfo atIndex:(nsInteger)ChangeType的sectionIndex:(NSFetchedResultsChangeType)类型{
开关(类型){
案例NSFetchedResultsChangesInsert:
如果(!((sectionIndex==0)和([self.tv numberOfSections]==1)))
[self.tv insertSections:[NSIndexSet IndexBethIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
打破
案例NSFetchedResultsChangeDelete:
如果(!((sectionIndex==0)和([self.tv numberOfSections]==1)))
[sel
didChangeObject
 case NSFetchedResultsChangeMove
 [self.tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:NO];

  [self.tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                           withRowAnimation:NO];
   if (indexPath && newIndexPath) {
                 [self.tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:NO];

                 [self.tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                           withRowAnimation:NO];
  } else {
                 NSLog(@"A table item was moved");
  }