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