【发布时间】:2017-04-06 18:31:33
【问题描述】:
我的 tableView 中有许多不同的类别部分是从名为 allProducts 的变量加载的,该变量包含我所有的 Realm 对象(Results<Product> 类型)。
然而,自从我介绍这段代码以来,每个部分都加载了正确的产品:
switch productViewSegmentedControl!.selectedSegmentIndex {
case 0:
allProductsInSection = allProducts.filter("itemgroup = %@", allProductSections[indexPath.section])
case 1:
allProductsInSection = allProducts.filter("itembrand = %@", allProductSections[indexPath.section])
case 2:
allProductsInSection = allProducts.filter("itemtype = %@", allProductSections[indexPath.section])
default:
allProductsInSection = allProducts.filter("itemgroup = %@", allProductSections[indexPath.section])
}
在我的 cellForRowAt indexPath 方法中,当滚动到 tableView 有很多项目的部分时,UI 会滞后。
tableView 中的每个单元格都包含let product = allProductsInSection![indexPath.row]。 product 常量保存了我的 Product 模型类中每个项目的属性。
我可以做些什么来提高 UI 的性能?
附:每个单元格都已被重复使用:
let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell") as? OrderFormViewCell
?? UITableViewCell(style: .subtitle, reuseIdentifier: "ProductCell") as! OrderFormViewCell
【问题讨论】:
标签: ios swift uitableview realm