【问题标题】:Custom uitabeviewcells blank when scrolling滚动时自定义uitableviewcell空白
【发布时间】: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` 方法中设置一旦滚动需要开始重用单元格,就会开始返回空值。

我对同时使用MagicalRecordsAFNetworking 不熟悉,所以也许我没有正确处理这些。以下是我如何将 CoreData 中的数据提取到我的NSMutableArray

- (void) fetchData {

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

非常感谢任何帮助!

【问题讨论】:

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


    【解决方案1】:

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

    例如 viewDidLoad 并在 cellForRowAtIndexPath 中:

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

    【讨论】:

    • 我已经在上面输入的 CellForRowAtIndexPath 代码中运行了该代码......还有其他想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2015-02-07
    相关资源
    最近更新 更多