Commit 09f0557e by Demid Merzlyakov

Fix occasional crash due to working with the UI from a background thread.

parent ef2c8a96
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import UIKit import UIKit
import CoreLocation import CoreLocation
import OneWeatherAnalytics import OneWeatherAnalytics
import OneWeatherCore
class TodayViewController: UIViewController { class TodayViewController: UIViewController {
//Private //Private
...@@ -63,8 +64,10 @@ class TodayViewController: UIViewController { ...@@ -63,8 +64,10 @@ class TodayViewController: UIViewController {
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator) super.viewWillTransition(to: size, with: coordinator)
coordinator.animate { _ in onMain {
self.tableView.reloadData() coordinator.animate { _ in
self.tableView.reloadData()
}
} }
} }
...@@ -82,7 +85,10 @@ private extension TodayViewController { ...@@ -82,7 +85,10 @@ private extension TodayViewController {
view.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor view.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
localizationObserver = NotificationCenter.default.addObserver(forName: .localizationChange, object: nil, queue: .main, using: { [weak self] _ in localizationObserver = NotificationCenter.default.addObserver(forName: .localizationChange, object: nil, queue: .main, using: { [weak self] _ in
self?.tableView.reloadData() onMain {
self?.tableView.reloadData()
}
}) })
} }
...@@ -176,10 +182,12 @@ extension TodayViewController: TodayViewModelDelegate { ...@@ -176,10 +182,12 @@ extension TodayViewController: TodayViewModelDelegate {
} }
func viewModelDidChange<P>(model: P) where P : ViewModelProtocol { func viewModelDidChange<P>(model: P) where P : ViewModelProtocol {
cityButton.configure(with: viewModel.location) onMain {
cityButton.isHidden = false self.cityButton.configure(with: self.viewModel.location)
tableView.isHidden = false self.cityButton.isHidden = false
tableView.reloadData() self.tableView.isHidden = false
self.tableView.reloadData()
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment