0
- (UITableViewCell *)tableView:... cellForRowAtIndexPath:... {
    // init and sanity check

    if (indexPath.row == 0) {
        // make cell look like a section header
        // easier and less complex than using a custom header view

        NSLog(@"header");
        // should prove that only four cells get the bg image
        // and yet, almost every time the table is reloaded
        // one more cell unexpectedly gets the background
        // without putting another line in the debugger
    } else {
        // normal cells after row 0
        // BUG: some of these are getting the row 0 background

        NSLog(@"row");
        // firing exactly the right number of times --
        // once for each row with an index greater than 0
        // so why are some of these cells getting the header bg?

        // when these cells get the headers' contents
        // they behave exactly as one would expect
        // except that they should be the normal rows
    }

    // misc stuff, not causing problems

    return cell;
}

没有强迫用户完全重新启动应用程序只是为了将不同的数据转储到表中,我不知道如何修复这个错误。

如果我折叠每个部分(即清空expandedSections集合并重新加载,只留下伪标题可见),问题就不那么严重了,但它并没有消失。


编辑:

初始加载:screenshot
重新加载后:screenshot
链接而不是图像,因为它是一个 iPad 应用程序。
使用一些虚拟内容进行测试。

这有什么帮助吗?我知道需要更多代码才能获得真正的帮助,但我不知道还要添加什么,缺少指向整个视图代码的链接。

4

2 回答 2

0

它可能与单元缓存有关......关于将图像设置为 row == 0 而不是清除它......但是由于您显示的代码数量有限,很难更具体。

于 2012-08-20T15:19:52.857 回答
0

您是否尝试过为第一个单元格设置不同的单元格标识符,为其余单元格设置另一个单元格标识符?tableView 在创建新单元格时重用相同的单元格类型,因此可能会使它们混淆。通过为每种类型使用不同的单元格标识符,它将准确地知道何时使用每个单元格。

于 2012-08-21T08:44:35.463 回答