【发布时间】:2015-05-08 09:30:55
【问题描述】:
我的表格视图中有 4 个部分,每个部分包含 2500 个单元格。加载大约需要 9 秒。我想异步填充 4 个部分,这可能吗?
编辑:现在填充表格视图的代码。
//Contains 2500 names each.
let namesForSection0:[String] = []
let namesForSection1:[String] = []
let namesForSection2:[String] = []
let namesForSection3:[String] = []
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: UITableViewCell = self.tableview.dequeueReusableCellWithIdentifier("catcell") as! UITableViewCell
switch indexPath.section {
case 1:
cell.textLabel?.text = namesForSection0[indexPath.row]
case 2:
cell.textLabel?.text = namesForSection1[indexPath.row]
case 3:
cell.textLabel?.text = namesForSection2[indexPath.row]
case 4:
cell.textLabel?.text = namesForSection3[indexPath.row]
default:
println("something is wrong")
}
}
【问题讨论】:
-
显示数据是什么以及您当前的操作方式。你有没有分析过什么是慢的?
-
@Wain 代码已发布。
-
你是如何计算单元格高度的?
-
@dan 除了使用 heightForRowAtIndexPath,所有单元格的高度都是 44。
-
那么哪个部分需要 4 秒?字符串是从哪里来的?
标签: ios uitableview swift asynchronous populate