ios - dequeueReusableCellWithIdentifier 快速加载需要时间

标签 ios uitableview swift

我的 UITableView 有问题。当 UIViewController 结束加载 UITableViewCell 时,第一次加载大约需要 4 秒 6 秒。当我再次调用我的 UIViewController 时,它已正确加载。我错过了什么 ?

任何帮助将不胜感激:)

加载UIViewController

override func viewDidLoad() {

    super.viewDidLoad()

    self.tableView.backgroundColor  = UIColor.blackColor()
    self.webview.backgroundColor    = PPP.COLOR.BackgroundDarkBrown
    self.webview.contentMode        = UIViewContentMode.ScaleAspectFit
    self.webview.suppressesIncrementalRendering = true        
    self.webview.alpha = 0
    self.tableView.alpha = 1

    self.tableView.registerNib(UINib(nibName: "SummaryProduct", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell1")
    self.tableView.registerNib(UINib(nibName: "SummaryOrder", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell2")
}

我对 TableView 的声明

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // FOR ORDER
    if section == 1 { return 1 }
    // FOR PRODUCT LIST
    let count = self.cart.getTotalProducts()
    if count > 0 { return count }
    return count
}

func tableViewForCellProduct(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as SummaryProductTableViewCell
    cell.configureCellWithIndexPath(self, indexPath: indexPath, cart: self.cart)
    return cell
}

func tableViewForCellOrder(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as SummaryOrderTableViewCell
    cell.configureCellWithIndexPath(self, indexPath: indexPath, cart: self.cart)
    return cell
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    switch indexPath.section {
    case 0:
        return self.tableViewForCellProduct(tableView, cellForRowAtIndexPath: indexPath)
    default:
        return self.tableViewForCellOrder(tableView, cellForRowAtIndexPath: indexPath)
    }
}

最佳答案

延迟可能是第一次加载单元格。第二次它们可能缓存在某个地方的 ram 中。

您可以通过在应用程序加载时在应用程序委托(delegate)中创建两个单元格来将延迟移至加载时间,这很可能会预先填充任何缓存,这意味着您的第一次使用将与第二次一样快。

关于ios - dequeueReusableCellWithIdentifier 快速加载需要时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29843885/

相关文章:

ios - iOS Safari 11.3 上的导航器中没有服务 worker

ios - swift UIGraphicsGetImageFromCurrentImageContext 无法释放内存

ios - UITabBarController 内的 UITableView 不工作

ios - Swift TableView 单元格播放按钮点击和其他单元格按钮需要重置

iphone - 找不到此可执行文件的有效配置文件 : only with distribution

ios - 核心数据模型设计

ios - 向左滑动时在 UITableViewCell 中自定义编辑 View 。 Objective-C 或 Swift

swift - 使用 UITableView iOS swift 以编程方式按下 UIViewController 的后退按钮

ios - 从 SceneKit 导出 USDZ 会导致模型变暗

ios - UITextField 中带有货币符号的点后 2 位小数的限制