簡體   English   中英

滾動多個單元格類型時,UITableView滯后

[英]UITableView lags when scrolling with multiple cell types

我知道有關此主題的問題很多,但請耐心等待,因為我沒有找到針對自己特定問題的解決方案。

首先,我的整個應用程序都在代碼中(沒有情節提要)。 我正在創建具有多種單元格類型的tableView(從后端從那里獲取數據)。 單元格處於恆定順序,這意味着第一個單元格將與其他任何第一個單元格始終具有相同的類型(不確定您是否明白我的意思,但是從技術上講,這些單元格類型對於特定的indexPath是恆定的。

所以問題是我有一些方法可以使每個indexPath的特定單元出隊。 在我的一個單元格中,我有一個MapboxStatic地圖,該地圖從Mapbox的服務器返回地圖的圖像。 假設在初始運行時該單元格不在屏幕上,如果我滾動得足夠快,tableView將延遲一秒鍾左右以加載返回的圖像(我嘗試在不做任何更改的情況下在主隊列上異步加載它)。

現在,我的另一個問題是使用UberRides按鈕,滾動時它也滯后了(同一問題)。

值得一提的是,如果我在tableView中滾動一次(有滯后),然后上下滾動它不再滯后,但我想這是因為出隊的單元格仍在內存中。

如果您需要任何其他詳細信息,請發表評論。

[編輯]代碼:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if indexPath.section == 1 {
        return reserveTableViewCell(at: indexPath)
    } else if indexPath.section == 2 {
        return dateTimeTableViewCell(at: indexPath)
    } else if indexPath.section == 3 {
        return descriptionTableViewCell(at: indexPath)
    } else if indexPath.section == 4 {
        if indexPath.row == 0 {
            return mapTableViewCell(at: indexPath)
        } else {
            return uberTableViewCell(at: indexPath)
        }
    } else {
        let cell = tableView.dequeueReusableCell(withIdentifier: defaultCell, for: indexPath)
        return cell
    }
}

private func reserveTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: reserveCell, for: indexPath) as! ReserveTableViewCell
    return cell
}

private func descriptionTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: descriptionCell, for: indexPath) as! DescriptionTableViewCell
    return cell
}

private func dateTimeTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: dateTimeCell, for: indexPath) as! DateTimeTableViewCell
    return cell
}

private func mapTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: mapCell) as! MapTableViewCell
    cell.detailController = self
    return cell
}

private func uberTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: uberCell, for: indexPath) as! UberTableViewCell
    return cell
}

最好

好吧,創建單元很慢。 現在知道要花多少時間很難給您任何建議。 使用時間分析器確定有問題的代碼。

如果不需要覆蓋,則可以嘗試使用MGLMapSnapshotter 是一個如何將MGLMapSnapshot與表視圖一起使用的示例。

暫無
暫無

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

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