修复学习记录页面返回后数据不刷新,改为 viewWillAppear 重新加载统计
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
final class HistoryViewController: UITableViewController {
|
final class HistoryViewController: UITableViewController {
|
||||||
private let sections: [(title: String, items: [LearnedRecord])]
|
private var sections: [(title: String, items: [LearnedRecord])] = []
|
||||||
private var speechObserver: NSObjectProtocol?
|
private var speechObserver: NSObjectProtocol?
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
sections = LearnedStore.shared.sectioned
|
|
||||||
super.init(style: .plain)
|
super.init(style: .plain)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +26,18 @@ final class HistoryViewController: UITableViewController {
|
|||||||
tableView.backgroundColor = .systemBackground
|
tableView.backgroundColor = .systemBackground
|
||||||
tableView.contentInset.top = 8
|
tableView.contentInset.top = 8
|
||||||
|
|
||||||
|
speechObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: SpeechService.speakingDidChangeNotification, object: nil, queue: .main
|
||||||
|
) { [weak self] _ in
|
||||||
|
for cell in self?.tableView.visibleCells ?? [] {
|
||||||
|
(cell as? WordCardCell)?.updateSpeakerState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
sections = LearnedStore.shared.sectioned
|
||||||
if sections.isEmpty {
|
if sections.isEmpty {
|
||||||
let label = UILabel()
|
let label = UILabel()
|
||||||
label.text = "暂无学习记录"
|
label.text = "暂无学习记录"
|
||||||
@@ -41,15 +52,10 @@ final class HistoryViewController: UITableViewController {
|
|||||||
label.centerYAnchor.constraint(equalTo: bg.centerYAnchor)
|
label.centerYAnchor.constraint(equalTo: bg.centerYAnchor)
|
||||||
])
|
])
|
||||||
tableView.backgroundView = bg
|
tableView.backgroundView = bg
|
||||||
|
} else {
|
||||||
|
tableView.backgroundView = nil
|
||||||
}
|
}
|
||||||
|
tableView.reloadData()
|
||||||
speechObserver = NotificationCenter.default.addObserver(
|
|
||||||
forName: SpeechService.speakingDidChangeNotification, object: nil, queue: .main
|
|
||||||
) { [weak self] _ in
|
|
||||||
for cell in self?.tableView.visibleCells ?? [] {
|
|
||||||
(cell as? WordCardCell)?.updateSpeakerState()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
|||||||
Reference in New Issue
Block a user