当我向上滚动并保持时,Tableview崩溃

时间:2014-02-06 18:04:27

标签: uitableview xcode5

我有一个由核心数据提供的表格视图。它工作正常,除非我滚动回顶部并将其保持在那里。然后应用程序崩溃了。 有什么建议? 感谢

//此类的模型。 // //当它被设置时,我们创建一个NSFetchRequest来获取与之关联的数据库中的所有摄影师。 //然后我们使用NSFetchedResultsController将NSFetchRequest挂钩到表视图。

- (void)setManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
{
    _managedObjectContext = managedObjectContext;
    if (managedObjectContext) {
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"TestResults"];
        request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];
        request.predicate = nil; // all records

        self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    } else {
        self.fetchedResultsController = nil;
    }
}

#pragma mark - UITableViewDataSource

// Uses NSFetchedResultsController's objectAtIndexPath: to find the Photographer for this row in the table.
// Then uses that Photographer to set the cell up.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestResults"];

    TestResults *testResult = [self.fetchedResultsController objectAtIndexPath:indexPath];

    [self showTestResult:testResult];


    // show traffic light color


    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MM-dd-yy hh:mm a"];
    NSString *theDate = [dateFormatter stringFromDate:testResult.date];

    cell.textLabel.text = theDate;
    cell.detailTextLabel.text = testResult.overallPassOrFail;

    NSLog(@"overall: %@", testResult.overallPassOrFail);
    NSLog(@"light color: %@", testResult.trafficLightColor);

    // retrieve an image
    if ([testResult.trafficLightColor isEqualToString:@"Red"]) {
        self.lightImage = @"Red_Light";
    } else if ([testResult.trafficLightColor isEqualToString:@"Yellow"]) {
        self.lightImage = @"Yellow_Light";
    } else {
        self.lightImage = @"Green_Light";
    }
    NSString *imagefile = [[NSBundle mainBundle] pathForResource:self.lightImage ofType:@"png"];
    self.imageOne = [[UIImage alloc] initWithContentsOfFile:imagefile];
    cell.imageView.image = self.imageOne;
    //

    return cell;
}

1 个答案:

答案 0 :(得分:0)

您正在调用未实现的方法,请检查您的代码;)