I have a TabelViewController. The data inside the TableViewCells is being updated with a high frequency (lets assume 10 Hz) via the tableview.reloadData(). This works so far. But when I scroll the TableView, the update is paused, until the user interaction ends. Also all other processes inside my app are paused. How can I fix this?
Here is an example TableViewController. If you run this on your emulator and check the output inside the debug area, you will notice, that not only the update of the graphics (here a label) is paused, but also the notifications, when you scroll and hold the tableview. This is also the case, if you have a process in another class.
It's interesting, that this blocking of processes is not the case if you interact with a MapView. What am I missing here?
import UIKit
class TableViewController: UITableViewController {
var text = 0
var timer = Timer()
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.recieveNotification), name: NSNotification.Name(rawValue: "testNotificatiion"), object: nil)
scheduledTimerWithTimeInterval()
}
func scheduledTimerWithTimeInterval(){
timer = Timer.scheduledTimer(timeInterval: 1/10, target: self, selector: #selector(self.updateCounting), userInfo: nil, repeats: true)
}
@objc func updateCounting(){
text += 1
let userInfo = ["test": text]
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "testNotificatiion"), object: nil, userInfo: userInfo)
tableView.reloadData()
}
@objc func recieveNotification(notification: Notification){
if let userInfo = notification.userInfo! as? [String: Int]
{
if let recieved = userInfo["test"] {
print("Notification recieved with userInfo: \(recieved)")
}
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell?
cell = tableView.dequeueReusableCell(withIdentifier: "rightDetail", for: indexPath)
cell?.detailTextLabel?.text = String(text)
return cell!
}
}