我遇到了開發我的iphone應用程序的主要問題。CoreData:錯誤:嚴重的應用程序錯誤。核心數據更改處理期間發生異常
這裏是完整的錯誤:
CoreData: error: Serious application error. Exception was caught during Core Data
change processing. This is usually a bug within an observer of
NSManagedObjectContextObjectsDidChangeNotification. -[TimeSpentStudying coordinate]:
unrecognized selector sent to instance 0x21db92d0 with userInfo (null)
這是奇怪,因爲我有兩個coreData實體(位置& TimeSpentStudying)。但我不認爲這是問題。 [TimeSpentStudying coordinate]
是奇怪的,因爲我不會對TimeSpentStudying
核心數據類發送的coordinate
屬性不
我有一個MapView的設置,並且當用戶點按詳細公開內容按鈕上的mkannotationview,一個新的視圖(LibraryTrackTimeViewController)啪啪但是幾乎不可用。我試圖在viewDidLoad中調用NSLog並沒有顯示出來。
mapViewController.m
#pragma mark - NSNotification
- (void)contextDidChange:(NSNotification *)notification
{
if ([self isViewLoaded]) {
[self updateLocations];
}
。
- (void)updateLocations
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSError *error;
NSArray * foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (foundObjects == nil) {
FATAL_CORE_DATA_ERROR(error);
return;
}
if (locations != nil) {
[self.mapView removeAnnotations:locations];
}
locations = foundObjects;
[self.mapView addAnnotations:locations];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.managedObjectContext];
}
我認爲錯誤可能在mapViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (distance < 500) {
if ([segue.identifier isEqualToString:@"TrackLibraryTimes"]) {
UINavigationController *navigationController = segue.destinationViewController;
LibraryTrackTimeViewController *controller = (LibraryTrackTimeViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
}}
我的粗略語法道歉與prepareForSegue方法做,我只是習慣到如此,如果你需要更多的代碼,請讓我知道,謝謝大家。
嗨,歡迎您!另外,很好的問題! – doge
錯誤消息清楚地表明'座標'消息被髮送到'TimeSpentStudying'的一個實例,可能是地址爲0x21db92d0的對象。所以在某些時候,你正在使用一個'TimeSpentStudying'對象來預期不同的類型('Locations'?)。由於Objective-C中的動態方法解析,這些問題通常只在運行時纔會顯示出來。您應該嘗試找出問題,例如通過設置所有Objective-C異常的斷點。 –