Skip to content

cell复用问题 #13

Open
Open
@cxm19881208

Description

@cxm19881208

设置enableCellReusable=true开启复用cell,
发现cell在视图上有一百多个。
`
guard let cell = obtainCell(with: danmaku) else { return }

    let shootTrack: DanmakuTrack
    if isOverlap {
        shootTrack = findLeastNumberDanmakuTrack(for: danmaku)
    } else {
        guard let t = findSuitableTrack(for: danmaku) else {
            delegate?.danmakuView(self, noSpaceShoot: danmaku)
            return
        }
        shootTrack = t
    }`

感觉问题在这几句代码,248行和256行。
先通过obtainCell获取一个cell,此时如果是从缓存中获取的,但是此时轨道没有空位,流程会在256行return,导致cell已经从缓存中移除,但是还在父view上。
是不是应该在方法func cellPlayingStop(_ cell: DanmakuCell)中,第633行下面加一句cell.removeFromSuperview()。

只复用对象就可以了,下次使用时重新add到父view。
或者调整shoot逻辑,先判断有空闲轨道,然后再获取cell。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions