Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我更改单元格的大小并重新加载时,为什么UITableView单元格的顺序会更改?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 当我更改单元格的大小并重新加载时,为什么UITableView单元格的顺序会更改?

Ios 当我更改单元格的大小并重新加载时,为什么UITableView单元格的顺序会更改?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我得到了一个tableView来显示一些信息,如下图所示 细胞在折叠状态下会膨胀,如下图所示。 如果您再次触摸它,它应该再次折叠,如图1所示 然后问题来了。 如图2所示,屏幕外侧有三个单元格。 外面是一号,二号,五号。还有里面的3号,4号。No3是我们刚刚接触过的细胞。 当我再次触摸No3电池将其折叠时,顺序变为No3、No4、No1、No2、No5。 屏幕内的单元格似乎已被提升到顶部。 我很困惑,到底发生了什么?如何避免? 单元格的高度取决于未更改的数据源,因此它会把事情搞砸 func ta

我得到了一个tableView来显示一些信息,如下图所示

细胞在折叠状态下会膨胀,如下图所示。 如果您再次触摸它,它应该再次折叠,如图1所示

然后问题来了。
如图2所示,屏幕外侧有三个单元格。
外面是一号,二号,五号。还有里面的3号,4号。No3是我们刚刚接触过的细胞。
当我再次触摸No3电池将其折叠时,顺序变为No3、No4、No1、No2、No5。

屏幕内的单元格似乎已被提升到顶部。 我很困惑,到底发生了什么?如何避免? 单元格的高度取决于未更改的数据源,因此它会把事情搞砸

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "WBCell") as! WBTableViewCell
        cell.controller = self

        let state = cellStates[indexPath.section]
        if state == .initial {
            let data = dataSource[index]
            cell.initial(data: data)
            cellStates[indexPath.section] = .fold
        } else if state == .fold {
            cell.switchTo(unFolded: false) // Update autolayout constrains via SnapKit
        } else {
            cell.switchTo(unFolded: true)
        }
        return cell
    }

您能在indexPath方法中向我展示CellForRow吗?另外,您想展开节还是行?@Paulw11每个节中只有一个单元格。您不需要在折叠和展开的情况下设置
data
属性。无法保证上次用于特定索引路径的单元格下次将用于该索引路径。您的
cellForRowAt
必须始终完全配置cell@Paulw11该单元将获取在线图像,因此,如果我每次都完全设置该单元,将花费很多(我还没有尝试过)。一旦我尝试,我会让你知道它是否有效`
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "WBCell") as! WBTableViewCell
        cell.controller = self

        let state = cellStates[indexPath.section]
        if state == .initial {
            let data = dataSource[index]
            cell.initial(data: data)
            cellStates[indexPath.section] = .fold
        } else if state == .fold {
            cell.switchTo(unFolded: false) // Update autolayout constrains via SnapKit
        } else {
            cell.switchTo(unFolded: true)
        }
        return cell
    }