簡體   English   中英

重新加載數據時 ios swift 4 中的 Tableview 閃爍

[英]Tableview flickers in ios swift 4 while reloading the data

我在 tableview 中有 4 個不同的單元格,它工作正常,但是當我重新加載單元格時,tableview 會閃爍,我該如何解決這個問題?

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

    let event = events[indexPath.section][indexPath.row]
    if event.hasTicketsStatus {
        if event.isShared{
            let cell = tableView.dequeueReusableCell(withIdentifier: "eventcellshared", for: indexPath as IndexPath) as! EventCellSharedEvents
            cell.initWithEvent(event: event)
            return cell
        }else{
            let cell = tableView.dequeueReusableCell(withIdentifier: "eventcell", for: indexPath as IndexPath) as! EventCell
            cell.eventVC = self
            cell.initWithEvent(event: event)
            return cell
        }
    }else{
        if isPastSelected{
            let cell = tableView.dequeueReusableCell(withIdentifier: "PastEventCellNoTicket", for: indexPath as IndexPath) as! PastEventCellNoTicket
            cell.pasteventOutTicketVC = self
            cell.initWithEvent(event: event)
            return cell
        }else{
            let cell = tableView.dequeueReusableCell(withIdentifier: "eventcellwithout", for: indexPath as IndexPath) as! EventCellWithOutTicket
            cell.eventOutTicketVC = self
            cell.initWithEvent(event: event)
            return cell
        }
    }
}

您可以在重新加載表格時嘗試以下代碼:

UIView.performWithoutAnimation {
    self.tableView.reloadData()
    self.tableView.beginUpdates()
    self.tableView.endUpdates()
}

如果這不起作用,您可以嘗試重新加載您打算進行更改的特定索引,而不是重新加載整個表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM