Ваш код не работает для меня. Может быть, вы пропустили что-то, чтобы упомянуть в своем вопросе. Но с информацией, которую я понял, я сделал некоторую модификацию, и теперь она работает (проверено в iPhone X), как и ожидалось. Ниже приведен рабочий полный исходный код.
import UIKit
class InsertCellViewController: UIViewController, UITableViewDataSource {
var dataArray:Array<String> = []
let reusableCellId = "AnimationCellId"
var timer = Timer()
var index = -1
@IBOutlet weak var tableView: UITableView!
// UIViewController lifecycle
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: reusableCellId)
tableView.separatorStyle = .none
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
updateTableView()
}
// MARK : UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reusableCellId)!
cell.textLabel?.text = dataArray[indexPath.row]
return cell
}
// Supportive methods
func updateTableView() {
timer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(updateCounting), userInfo: nil, repeats: true)
}
@objc func updateCounting(){
if index == 19 {
timer.invalidate()
}
index += 1
let indexPath = IndexPath(row: index, section: 0)
self.tableView.beginUpdates()
self.dataArray.append(String(index))
self.tableView.insertRows(at: [indexPath], with: .fade)
self.tableView.endUpdates()
}
}