Ios 岩芯数据中截面的零值

Ios 岩芯数据中截面的零值,ios,iphone,objective-c,uitableview,core-data,Ios,Iphone,Objective C,Uitableview,Core Data,在测试了一些新特性之后,我遇到了一个看起来很奇怪的核心数据错误 CoreData: error: (NSFetchedResultsController) A section returned nil value for section name key path 'date'. Objects will be placed in unnamed section 如果我滚动到我的UITableView的顶部,我会看到单元格中有NULL值 让我向你介绍我的情况。在这个UITableView的第

在测试了一些新特性之后,我遇到了一个看起来很奇怪的核心数据错误

CoreData: error: (NSFetchedResultsController) A section returned nil value for section name key path 'date'. Objects will be placed in unnamed section
如果我滚动到我的
UITableView
的顶部,我会看到单元格中有
NULL


让我向你介绍我的情况。在这个
UITableView
的第一次(有史以来)
vieddiload
上,我从服务器下载数据,解析数据并加载到核心数据中。挺直的吧?但每次查看此
viewdiload
时,我都会检查此实体中是否已经存储了某些内容,如果已经存储了,我会滚动到距离当前日期最近的行。为了实现这一点,我使用了我编写的方法:

- (void)scrollToNearestDateInFutureWithAnimation:(BOOL)animation
{
    // Saving present date for comparison purposes
    NSDate *presentDate = [NSDate date];
    // Making a big interval (2001)
    double interval = fabs([NSDate timeIntervalSinceReferenceDate]);

    // Getting managed object to hold the proper row
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Activity" inManagedObjectContext:self.moc];
    Activity *nearestActivity = [[Activity alloc] initWithEntity:entity insertIntoManagedObjectContext:self.moc];

    // Iterating each activity in fetched objects
    for (Activity *activity in [self.fetchedResultsController fetchedObjects]) {
        // Getting time interval between present date and activity start date
        double activityIntervalSincePresent = [activity.startDate timeIntervalSinceDate:presentDate];

        // Checing if interval is smaller than default one and is bigger than 0 (eliminating past dates)
        if (interval > activityIntervalSincePresent && activityIntervalSincePresent > 0) {
            interval = activityIntervalSincePresent;
            nearestActivity = activity;
        }
    }

    // Scrolling to the row
    [self.tableView scrollToRowAtIndexPath:[self.fetchedResultsController indexPathForObject:nearestActivity] atScrollPosition:UITableViewScrollPositionTop animated:animation];
}
以及
viewDidLoad
的一部分,负责检查核心数据中实体的存在:

if ([self coreDataHasEntriesForEntityName:@"Timetable"]) {
        // NSLog(@"Core Data has entries");
        NSError *error;
        if (![[self fetchedResultsController] performFetch:&error]) {
            // Update to handle the error appropriately.
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        }

        // Scrolling to row with nearest date in future
        [self scrollToNearestDateInFutureWithAnimation:NO];

        // Checking for new timetable
        [self checkForTimetableUpdatesWithVersions:[self getTimetableVersions]];
    } else {
        // NSLog(@"No entries in Core Data");
        if ([self registeredTimetableExistsInUserDefaults]) {
            self.timetableID = [[NSUserDefaults standardUserDefaults] valueForKey:TIMETABLE_ID];
            [self showDownloadTimetableActionSheet];
        } else {
            [self showRegisterTimetableActionSheet];
        }
    }

对我来说,似乎有时候
[[self-fetchedResultsController]performFetch:&error]
不会停止它的工作,我希望它滚动到特定的行。。。但我可能完全错了这个猜测。我想不出更多的解决办法了。请帮帮我

就您的目的而言,这一行是错误的:

Activity *nearestActivity = [[Activity alloc] initWithEntity:entity insertIntoManagedObjectContext:self.moc];
因为它正在向数据存储中插入一个您不想要的空对象。你应该做的只是:

Activity *nearestActivity = nil;
似乎有一种常见的误解,即您需要使用对象引用初始化指针才能使其有效,但您没有,所以也没有,因为这是浪费(并且在您的情况下是腐败的)