- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 UITableView
显示核心数据项,之前通过数组 Hook 没有任何问题。然后,根据 Apple 和斯坦福的建议,我转向 CoreDataTableViewController
,直接通过 NSFetchedResultsController
将 Core Data 与 UITableView
集成。我已将 CoreDataTableViewController
添加到我的项目并将我原来的 TVC 的父类(super class)更改为新的 CDTVC。
我现在遇到屏幕外单元格的问题,其中一些是灰色的,上面有错误的数据。它可能与重复使用这些单元格有关,但我无法找出解决方案。有任何想法吗?谢谢。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
Period *displayPeriod = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
cell.textLabel.text = [dateFormatter stringFromDate:displayPeriod.date];
NSError *error = nil;
NSUInteger logbookCount = [self.managedObjectContext countForFetchRequest:self.fetchedResultsController.fetchRequest error:&error];
if (indexPath.row == logbookCount - 1) {
cell.detailTextLabel.text = @"";
} else {
int difference;
NSIndexPath *nextRow = [NSIndexPath indexPathForItem:indexPath.row + 1 inSection:indexPath.section];
Period *periodOne = [self.fetchedResultsController objectAtIndexPath:nextRow];
Period *periodTwo = [self.fetchedResultsController objectAtIndexPath:indexPath];
difference = [self dateDiffrenceFromDate:periodOne.date second:periodTwo.date];
cell.detailTextLabel.text = [self formatDifferenceToString:difference];
if (difference > 45 || difference < 21) {
cell.detailTextLabel.textColor = [UIColor colorWithRed:255/255.0 green:59/255.0 blue:48/255.0 alpha:1.0];
} else {
cell.detailTextLabel.textColor = [UIColor colorWithRed:142/255.0 green:142/255.0 blue:147/255.0 alpha:1.0];
}
}
return cell;
}
截图:
最佳答案
我不知道你的情况如何。根据我的意见和您的回答,您在与核心数据相关的内容中看不到任何错误。无论如何,我看不到任何与单元格创建相关的代码。另外,你说你没有使用 registerClass
方法。因此,我会尝试两种解决方案。
以显式方式使用 registerClass
(从 iOS 6 开始)。
- (void) viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier ];
}
或者只是创建带有 if 子句的单元格。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(!cell) {
cell = // create the cell here
}
// configure the cell here
关于ios - 带有 NSFetchedResultController 的 TableView 在屏幕外显示损坏的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20616861/
我有一个 NSFetchedResultsController,它取自一个 azure 的示例。它运行良好并且可以正确地从数据库中获取数据,但是如果我退出应用程序并从数据库中删除记录,它们仍然会显示在
我有一个实体 Person。 Person 与实体 ObjectA、ObjectB 和 ObjectC 具有三种关系。 我可以使用 NSFetchedResultController 按类型对它们进行
你好,我的核心数据表有问题,类似这样 +-----------------------+ |person | +-----------------------+ |na
我有以下数据模型: [Agency] > [AgencyRating] [RatingType] 评级类型有很多(例如总体、品牌、设计、编程等)。每个 agency 都可以拥有所有这些评级类型(例如
我对 NSFetchedResultController 有疑问。我有一个按钮可以将两个值保存到核心数据:actualDate 和 shortDate。 actualDate 是一个 NSDate 变
我正在检查 iPhone 核心数据项目的默认 Xcode 模板。在返回获取的结果 Controller 的方法中,我看到了这个: - (NSFetchedResultsController *)fet
我应该如何通过第一个属性获取数据并对第二个属性的值求和? 通过简单的获取我有: 但我只需要在 1 行中显示相同的 ZINGREDIENT 并对 ZCOUNT 的值求和: 就像: select ZING
我有两个表 - master 和 details - 彼此相关(一个 Master - 许多 Details) 我想显示 Details 表中的记录列表,按 Master 表中的“日期”字段排序。 如
我在 中有基类 Worker 和子类 Employee、Bookkeeper 和 Director 以及它们的实体>xcdatamodeld。现在我想使用 NSFetchedResultControl
我想做的事情很简单。在我的 UITableViewController 中,我想从多个 NSFetchedResultController 加载数据(我的数据模型中有多个实体),并将每个实体的数据放入
我想在 UITableview 的单独部分中显示 NSFetchedresultController 的结果。 最佳答案 您始终可以使用 访问 NSFetchedResultsController 获
问题: 在我的 CoreData 模型中,我有两个名为 List 和 Item 的实体,它们具有一对多关系。我当前的设计中有两种类型的列表,系统列表和用户列表。系统列表是系统在首次启动时创建的,用户列
如果用户点击操作表,我想用不同的谓词刷新 NSFetchedResultController。 代码如下: lazy var fetchResultController: NSFetchedResul
我在我的项目中使用 NSFetchedResultController。以下是我想要实现的场景。 我有一个名为Contact 的表,其中有两个属性LastMessageDate 和ContactNam
我想使用 NSFetchedResultsController 和 NSSortDescriptor 提供自定义排序。 由于无法通过 NSSortDescriptor 消息 -(id)initWith
我尝试在大型核心数据库(32000个对象)中创建搜索,但是当我向 UISearchBar 添加一些文本时,我有一些滞后(因为我的数据库正在使用新的搜索谓词进行更新)解决这个问题?我如何在后台线程中更新
假设有一个名为 testTable 的表: (NSNumber*) numValue (NSString*) stringValue 那么假设里面大概有50条记录。 numValue 每条记录都不一样
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve
我在 UICollectionviewController 中显示了一个数据集,我使用 [fetchedResultsController objectAtIndexPath:indexPath] 访
我有 UITableView 显示核心数据项,之前通过数组 Hook 没有任何问题。然后,根据 Apple 和斯坦福的建议,我转向 CoreDataTableViewController,直接通过 N
我是一名优秀的程序员,十分优秀!