NSFetchedResultsController返回具有null属性的对象

时间:2012-04-05 03:18:17

标签: objective-c ios cocoa-touch core-data

所以我正在使用带有Core Data的mogenerator,当我第一次加载tableview时,resultsController返回带有有效属性的好对象。但是当我滚动表时,所有重新加载的单元格都填充了从resultsController返回的具有null属性的对象。这是一些缓存问题吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    Log *log = [self.resultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%@", log.text];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

1 个答案:

答案 0 :(得分:0)

原来我不应该将resultsController放在viewWillLoad或viewDidLoad中。我把它放入了自己的访问方法中,现在工作正常。

相关问题