【发布时间】:2014-03-22 23:51:05
【问题描述】:
我有两个自定义UITableViewCells 我正在尝试使用MagicalRecord 从我从CoreData 提取的数组中填充。前三行数据出现(视图加载时最初可见的单元格),但是当我滚动下面的单元格时,没有任何数据填充到其中。此外,当我向上滚动最初显示数据的单元格时,现在是空白的。因此,当任何单元格被重用时,它似乎正在发生。我一直在绞尽脑汁,对解决问题的所有尝试都一无所获。这是我的cellForRowAtIndexPath 代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Explore *explore = [self.exploreCellData objectAtIndex:[indexPath row]];
if ([explore.belief_id isEqualToString:@"0"]) {
ExploreVoteCell *cell = (ExploreVoteCell *) [tableView dequeueReusableCellWithIdentifier:@"ExploreVote" forIndexPath:indexPath];
[cell.topicTitle setText:[explore topic_title]];
[cell.votesCount setText:[explore calc_totalVotes]];
[cell.timeDayCount setText:[explore day_difference]];
return cell;
} else {
ExploreBeliefCell *cell = (ExploreBeliefCell *) [tableView dequeueReusableCellWithIdentifier:@"ExploreBelief" forIndexPath:indexPath];
[cell.topicTitle setText:[explore topic_title]];
return cell;
}}
当我计算数组中的记录数(对于行数)或NSLog 一些数据元素时,当表格视图加载数据时,数据就在那里。但是,当我滚动 NSLog 时,我在 'cellForRowAtIndexPath` 方法中设置一旦滚动需要开始重用单元格,就会开始返回空值。
我对同时使用MagicalRecords 和AFNetworking 不熟悉,所以也许我没有正确处理这些。以下是我如何将 CoreData 中的数据提取到我的NSMutableArray
- (void) fetchData {
self.exploreCellData = [NSMutableArray arrayWithArray:[Explore MR_findAllSortedBy:@"calc_totalVotes" ascending:YES]];}
非常感谢任何帮助!
【问题讨论】:
标签: core-data uitableview ios7 magicalrecord afnetworking-2