iphone - UITableView 单元格最初正确加载,但随后发生变化

标签 iphone objective-c cocoa cocoa-touch

以下方法将数据从数组加载到 UITableView 的自定义单元格中。数据已正确加载。但是,当我向下滚动上述单元格中的数据(单元格不可见)时,它们会更改为数组中看似随机的元素。

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

    cellComments=nil;
    cellComments=(FullCommentCell *)[tableView dequeueReusableCellWithIdentifier:FullCommentCell_ID];
    if(cellComments==nil)
    {
        [[NSBundle mainBundle]loadNibNamed:@"FullCommentCell" owner:self options:nil];
    }
    NSString *row = [NSString stringWithFormat:@"#%i",indexPath.row+1];
    [cellComments loadFullComments:[latestFMLComments objectAtIndex:(indexPath.row+1)] withCommentNumber:row];
    //cellComments.userInteractionEnabled=NO;
    return cellComments;
}

我还有以下方法可以在单击单元格时进行处理。当单元格的数据更改为数组中的某个随机元素时 - 如果我单击单元格(调用下面的方法),单元格中的数据将更改为正确的数据。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self tableView:tableView cellForRowAtIndexPath:indexPath];
}

有什么想法为什么会发生这种情况吗?

最佳答案

您正在使用缓存的单元格,很可能您没有在 loadFullComments 中正确重置单元格的 subvview 元素。

关于iphone - UITableView 单元格最初正确加载,但随后发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/723723/

相关文章:

iphone - iPhone:如何在WebView中设置字体大小?

iphone - 如何为文档集生成 ctags 文件? (对于 Vim )

iphone - NSFetchedResultsController 部分按动态条件分组?

ios - Swift UICollectionView Cells 移动/UIButton 标签在 ReloadData 上闪烁

ios - 将工具栏中的栏按钮放置在 Storyboard的中心(纵向和横向)

objective-c - stringByReplacingOccurrencesOfString 不起作用?

objective-c - Cocoa Webview - 伪装 webview 作为原生控件

macos - 在 Swift 中创建像这样的普通框窗口吗?

swift - ( cocoa 错误1570。), "NSValidationErrorKey"错误

iphone - 如何将图像数据和网站URL一起发布在我的Facebook墙上