简而言之,I ve创建了数据库检索习惯方法:
+(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;
}
i 然后在这种方法中使用上述方法:
-(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;
}
问题在于,当用户改变LPVisit表格,并忆及这一方法显示这些变化时,它便会错失申请。
[EDIT]
其产生的例外是:
-[__NSArrayM objectID]: unrecognized selector sent to instance 0x4dac1f0
我认为这一错误是行的:
NSMutableArray *data = [[[CoreDataAccess recordsForTable:@"LPVisit" stringPredicate:onlyGetSavedVisitObjects] mutableCopy] autorelease];
如果我去掉自动释放,我就会发现一个记忆泄露,但申请确实发生故障。
是否有任何人事先了解情况