好吧,ios 6核心數據「CoreData:錯誤:嚴重的應用程序錯誤。」
這是我有史以來第一篇文章。幾小時後,我一直在頭撞牆。我討厭輸入問題;你可以相信我已經徹底試圖找出自己的想法。我對以下錯誤做了一些研究,但是我仍然無法解決它。這就是說,我是noob iOS 6開發人員,並且在覈心數據方面存在問題。錯誤是:
「CoreData:錯誤:嚴重的應用程序錯誤,在覈心數據更改處理過程中發生異常,這通常是NSManagedObjectContextObjectsDidChangeNotification觀察者中的一個錯誤,ALL或ANY操作符的左側必須是NSArray或NSSet與用戶信息(空)「
現在,我的數據模型如下:我有兩個實體(一對多關係)。這種關係是行爲 - >事件,其中有0個事件發生的未綁定事件。
我做的是這個;
在行爲表視圖控制器,我填充一個NSFetchedResultsController類似如下:
- (NSFetchedResultsController *)fetchedResultsController {
NSLog(@"Started Fetching In Behaviors...");
if (fetchedResultsController != nil) {
return fetchedResultsController;
}
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =
[appDelegate managedObjectContext];
NSEntityDescription *entityDesc =
[NSEntityDescription entityForName:@"Behavior"
inManagedObjectContext:context];
[fetchRequest setEntity:entityDesc];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
return fetchedResultsController;
}
所有這一切工作正常,虎背熊腰,腳蹬dory的。表填充沒有問題。現在,當選擇一個單元格我做什麼,我實例化另一個UITableViewCell的控制器,
{
NSLog(@"A value was selected from the table view");
IncidentsViewController *vc = [[IncidentsViewController alloc] initWithStyle:UITableViewStylePlain];
vc.managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
vc.parentRelationship = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSLog(@"Managed set on Incidents View Controller: %@", vc.managedObject);
NSString* name = [[NSString alloc] initWithString:[[vc.managedObject valueForKey:@"name"] description]];
NSLog(@"Name of selected object: %@", name);
[self.navigationController pushViewController:vc animated:YES];
}
從上面下IncidentsViewController具有基本上完全相同的fetchedResultsController。我將粘貼它的完整性。
- (NSFetchedResultsController *)fetchedResultsController2 {
NSLog(@"Started Fetching Resuts from Incidents View Controller...");
if (fetchedResultsController2 != nil) {
NSLog(@"fetchedResultsController not null");
return fetchedResultsController2;
}
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =
[appDelegate managedObjectContext];
NSEntityDescription *entityDesc =
[NSEntityDescription entityForName:@"Incident"
inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entityDesc];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"when" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSLog(@"parent relationship: %@", self.parentRelationship);
NSLog(@"managed object: %@", self.managedObject);
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY relationship == %@", self.parentRelationship]];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController2 = aFetchedResultsController;
/*
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
self.fetchedResultsController.delegate = self;
*/
NSLog(@"Ending fetching results from incidents controller...");
return fetchedResultsController2;
}
我的問題很簡單如下:當我有行
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ANY relationship == %@", self.parentRelationship]];
在第二個視圖控制器,一切都被在表中填寫正確的(即僅用於爲特定的行爲事件選擇出現在列表中,如果這條線存在,並且我嘗試向Incidents實體添加一條新記錄,則拋出上面的錯誤,如果我刪除了這條特定行,每一行都出現在列表中但是,當我嘗試向事件表添加某些內容時,該錯誤實際上是在BehaivorViewController中引發的;這是非常令人驚訝,因爲我實例化了新的NSFetchedResultsController,AppDelegate和NSManagedObjectContext,它們對於每個相應的視圖控制器都是特定的本地的。在我看來,這兩個是相互關聯的,雖然我似乎無法弄清楚。是否有可能對知道一些關於核心數據的人有所瞭解。我已爲我的完整的項目到以下網址:
https://webshare.uchicago.edu/users/dansully/Public/Dirty.zip
有問題的線是線310 IncidentsViewController.m。
非常感謝您幫助我回答我的問題。我將繼續努力,如果我找到解決方案,我會報告回來。
+1 yep。這是實際的問題。 – 2013-03-14 08:42:07
給那個人一支雪茄。 – dps 2013-03-14 15:52:56