滚动时自定义uitableviewcells为空白

时间:2014-03-22 23:51:05

标签: core-data uitableview ios7 magicalrecord afnetworking-2

我有两个自定义UITableViewCells我正在尝试使用CoreDataMagicalRecord提取的数组填充。出现前三行数据(在视图加载时最初可见的单元格)但是当我滚动时,下面没有任何单元格填充任何数据。此外,当我向上滚动单元格时,最初显示的数据现在为空白。所以当任何细胞被重复使用时似乎正在发生。我一直在努力解决问题。这是我的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`方法中时,一旦滚动需要开始重用单元格,就会开始返回空值。

我是使用MagicalRecordsAFNetworking的新手,所以也许我没有正确处理这些问题。以下是我将CoreData中的数据提取到NSMutableArray

的方法
- (void) fetchData {

self.exploreCellData = [NSMutableArray arrayWithArray:[Explore MR_findAllSortedBy:@"calc_totalVotes" ascending:YES]];}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

尝试使用:
     [tableView registerClass:[YOURCUSTOMCELL class] forCellReuseIdentifier:@“CUSTOMIDENTIFIER”];

在例如viewDidLoad中 并在cellForRowAtIndexPath中:

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

    return cell
}