Iphone NSFetchedResultsController对象索引路径崩溃(EXC\u错误访问)

Iphone NSFetchedResultsController对象索引路径崩溃(EXC\u错误访问),iphone,objective-c,core-data,nsfetchedresultscontroller,Iphone,Objective C,Core Data,Nsfetchedresultscontroller,我对NSFetchedResultsCOntroller有一个很大的问题。我使用的是FetchedResultsContrrioller,我有3个选项卡的界面。他们也使用核心数据。但我只有一个问题 Faktura *faktura = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.textLabel.text = faktura.NumerFV; // THE CRASH IS HERE int produ

我对NSFetchedResultsCOntroller有一个很大的问题。我使用的是FetchedResultsContrrioller,我有3个选项卡的界面。他们也使用核心数据。但我只有一个问题

Faktura *faktura = [self.fetchedResultsController objectAtIndexPath:indexPath];

cell.textLabel.text = faktura.NumerFV; // THE CRASH IS HERE

int productsCount = [faktura.Produkty count]; // OR HERE
NSString *kontrahentName = [faktura.Kontrahent valueForKey:@"NazwaKrotka"]; // OR HERE

cell.detailTextLabel.text = [NSString stringWithFormat:@"nabywca: %@, produktów: %d",kontrahentName, productsCount];

cell.imageView.image = [UIImage imageNamed:@"faktura_cell_image.png"];
cell.hidesImageWhileEditing = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Faktura
是我的NSManagedObject子类

僵尸说:
-[CFDictionary retain]:发送到解除分配实例0x5d619d0的消息

我的fetchedResultsController实现:

- (NSFetchedResultsController *)fetchedResultsController {

if (__fetchedResultsController != nil) return __fetchedResultsController;

// Setup the table

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Faktura" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

// Setup the sort descriptors

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"DataWystawienia" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];

// Create the fetched results controller

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

[aFetchedResultsController release];
[fetchRequest release];
[sortDescriptor release];
[sortDescriptors release];

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) { // THE CRASH IS HERE UNLESS I INIT NSFetchedResultsController WITH cacheName:nil. (IF IT'LL BE cacheName:@"Root" IT CRASHES.)

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Błąd Krytyczny" message:@"Wystąpił nieznany błąd przy zmienianiu zawartości w bazie danych. Dla dobra twoich danych prosimy niezwłocznie wyjść z aplikacji i spróbować ponownie." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return __fetchedResultsController;
} 
Faktura.h

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@interface NSArrayToDataTransformer : NSValueTransformer @end
@interface NSDictionaryToDataTransformer : NSValueTransformer @end

@interface Faktura : NSManagedObject

@property (nonatomic, retain) NSDate * DataZaplaty;
@property (nonatomic, retain) NSString * NumerFV;
@property (nonatomic, retain) NSDate * DataWystawienia;
@property (nonatomic, retain) NSDate * DataSprzedazy;
@property (nonatomic, retain) id Produkty;
@property (nonatomic, retain) id Kontrahent;

@end
My
Faktura
对象插入代码

- (void)fakturaCreator:(FakturaCreator *)form didEndWithValues:(NSDictionary *)values {

    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
    Faktura *newFaktura = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];

    [newFaktura setNumerFV:[values valueForKey:@"id"]];
    [newFaktura setDataWystawienia:[values valueForKey:@"creationDate"]];
    [newFaktura setDataSprzedazy:[values valueForKey:@"sellDate"]];
    [newFaktura setDataZaplaty:[values valueForKey:@"paymentDate"]];
    [newFaktura setKontrahent:[values valueForKey:@"kontrahent"]];
    [newFaktura setProdukty:[values valueForKey:@"produkty"]];

    NSError *error = nil;
    if (![context save:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    [self.emptySectionView setHidden:YES];
}
FakturaCreator
是我的UIViewController,用户在其中创建发票。值数组包含值字典:我的发票编号(
NSString
)、各种日期(
NSDate
)、客户端(
NSDictionary
)和产品(
NSArray

请帮帮我! 如果你需要一些额外的代码,我会把它放在这里

编辑:它肯定是对象索引路径:错误。当我注释所有单元格设置代码(它将显示空单元格),然后尝试删除该单元格时,应用程序在包含
objectatIndexPath:
的行上崩溃


编辑#2:有人吗?请帮帮我…:(

将值转换器包含到类中以及使用
+初始化
是非标准的。虽然
+初始化
应该可以工作,但在核心数据文档中建议不要使用任何类型的初始化方法,而是依赖
awakeFromFetch
进行初始化


我会检查您的tableview方法,例如:numberOfRowsInSection:以确保您从tableview获取正确的索引。如果tableview中的行和
获取的对象的计数不同步,您可能会遇到这种崩溃。

我想我看到了问题。在您的
NSArrayToDataT中变压器
,您有:

- (id)reverseTransformedValue:(id)value {
    NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:value];
    return [array autorelease];
}

由于
unarchiveObjectWithData:
不以“alloc”、“new”、“copy”或“mutableCopy”开头,您不拥有该对象,因此可能无法自动释放它。您的
NSDictionaryToDataTransformer

中也存在同样的问题。是否可以发布
fetchedResultsController
的实现?是否使用
@属性(非原子,保留)NSFetchedResultsController*fetchedResultsController;
在你的头文件中?还是
assign
?那么那部分看起来很好…下一个嫌疑犯可能是你的
Faktura
类。你介意把它的.h和.m文件贴出来吗?贴出来。我用它来转换可转换的值。我认为这不是
Faktura
错误。当我使用
NSManagedObject*faktura=[self.fetchedResultsController对象索引路径:indexPath];
而不是
faktura*faktura=[self.fetchedResultsController对象索引路径:indexPath];
,结果是相同的,但有一个问题,因为fetchedResultsController返回实际行数。NSManagedObject使我的应用程序崩溃。我将检查awakeFromFetch方法并写入结果。不……相同的结果。我将发布Faktura对象插入代码。可能有问题。是的!!!我忘记了无法发布的事实我没有的东西。现在它工作了!谢谢,谢谢谢谢!:)我会在19小时后给你+50:/
- (id)reverseTransformedValue:(id)value {
    NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:value];
    return [array autorelease];
}