0

嘿,我为数据库访问创建了一个自定义检索方法:

+(NSArray*) recordsForTable:(NSString *)table predicate:(NSPredicate *)prd{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    [fetchRequest setEntity:entity];

    [fetchRequest setPredicate:prd];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

然后我在这个方法中使用上述方法:

-(NSArray *)tableViewControllerData{

    NSNumber *savedBool = [[NSNumber alloc] initWithBool:YES];

    NSString *onlyGetSavedVisitObjects = [NSString stringWithFormat:@"bolSaved=%@", savedBool];
    [savedBool release];
    NSMutableArray *data = [[[CoreDataAccess recordsForTable:@"LPVisit" stringPredicate:onlyGetSavedVisitObjects] mutableCopy] autorelease];
    NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dteVisitDate" ascending:NO];
    NSArray *descriptors = [NSArray arrayWithObjects:dateDescriptor, nil];
    [data sortedArrayUsingDescriptors:descriptors];

    return data;    
}

遇到的麻烦是,当用户对 LVisit 表进行更改并调用此方法以显示这些更改时,它会使应用程序崩溃。

[编辑]

它产生的异常是:

 -[__NSArrayM objectID]: unrecognized selector sent to instance 0x4dac1f0

我相信错误在于:

NSMutableArray *data = [[[CoreDataAccess recordsForTable:@"LPVisit" stringPredicate:onlyGetSavedVisitObjects] mutableCopy] autorelease];

如果我删除自动释放,我会发生内存泄漏,但应用程序不会崩溃。

有没有人有什么见解,提前谢谢

4

1 回答 1

0

可变复制是否有可能抛出异常,因为*recordsis nil?如果@"bolSaved=%@"是拼写错误并且应该是 ,则可能会发生这种情况@"boolSaved=%@"

于 2011-03-21T14:58:33.127 回答