更快地填充UITableView的方法?

时间:2015-03-06 17:42:10

标签: ios uitableview swift asynchronous populate

我的tableview中有4个部分,每个部分包含2500个单元格。加载大约需要9秒钟。我想异步填充4个部分,这可能吗?

编辑:现在填写tableview的代码。

//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")

    }

}

1 个答案:

答案 0 :(得分:0)

解析JSON时,首先为每个阵列加载前50个成员。不要立即解析所有内容。数组需要是可变的,即var namesForSection0:[String] = [],而不是let。重新加载tableview。

然后解析完整的JSON并将新成员添加到数组中。请确保不要添加重复项(这是特定于您的数据)。加载后,在tableview上调用reloadData。