Reload data of UITableView in background

前端 未结 4 915
夕颜
夕颜 2021-02-04 14:52

In my app, I have a UITableViewController.

Its tableView is divided in 3 sections.

I download datas for each of those sections from my server. To do this, I have

4条回答
  •  伪装坚强ぢ
    2021-02-04 15:01

    So your "background thread" is actually your main thread. You have to use dispatch_get_global_queue and specify a priority to actually get a different thread. Also, the dispatch async in viewDidLoad is useless as all view controller lifecycle methods are called in the main thread. I would recommend doing something as follows in your f1, f2 and f3 methods:

    Start by launching an asynchronous url request, then in the completion block, update arrayX and reload a particular section of your tableview. This way all three requests can happen simultaneously and the table just updates the necessary data when each one finishes. Alternatively, if you only want to reload once, just replace the concurrentQueue variable you have with a background thread and then perform [tableView reloadData] on the main thread.

提交回复
热议问题