Created
September 10, 2018 16:30
-
-
Save daoseng33/f762d36ea09ddf1750096497a892371a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DispatchQueue.global(qos: .background).async { // 背景線程 | |
let initialIndex = self.datas.count // 原本已有的 20 筆資料 | |
var indexPaths: [IndexPath] = [] // 將要加入新項目的懵懂 array | |
for index in 0..<newPackOfDatas.count { // 將 indexPaths 加入新的 20 筆資料 | |
let indexPath = IndexPath(item: initialIndex + index, section: 0) // 注意起始位置是 20(initialIndex 為還沒更新前的資料 count) | |
indexPaths.append(indexPath) | |
} | |
self.datas += newPackOfDatas // 將新的資料加入 datas | |
DispatchQueue.main.async { // 切回主線程 | |
self.tableView.insertItems(at: indexPaths) // 安心的插入吧(?) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment