有子分类的类别改为面板入口,点击后进入子分类列表页再进入单词列表
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,12 @@ final class CategoryListViewController: UITableViewController {
|
|||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
Haptics.selection()
|
Haptics.selection()
|
||||||
let category = store.categories[indexPath.row]
|
let category = store.categories[indexPath.row]
|
||||||
navigationController?.pushViewController(
|
if let subs = category.subcategories, !subs.isEmpty {
|
||||||
WordListViewController(category: category, colorIndex: indexPath.row), animated: true)
|
let vc = SubcategoryListViewController(category: category, colorIndex: indexPath.row)
|
||||||
|
navigationController?.pushViewController(vc, animated: true)
|
||||||
|
} else {
|
||||||
|
navigationController?.pushViewController(
|
||||||
|
WordListViewController(category: category, colorIndex: indexPath.row), animated: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import UIKit
|
||||||
|
|
||||||
|
final class SubcategoryListViewController: UITableViewController {
|
||||||
|
private let category: WordCategory
|
||||||
|
private let colorIndex: Int
|
||||||
|
private let subcategories: [Subcategory]
|
||||||
|
|
||||||
|
init(category: WordCategory, colorIndex: Int) {
|
||||||
|
self.category = category
|
||||||
|
self.colorIndex = colorIndex
|
||||||
|
self.subcategories = category.subcategories ?? []
|
||||||
|
super.init(style: .plain)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, unavailable)
|
||||||
|
required init?(coder: NSCoder) { fatalError() }
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
title = category.name
|
||||||
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
|
tableView.register(CategoryCardCell.self, forCellReuseIdentifier: "cell")
|
||||||
|
tableView.separatorStyle = .none
|
||||||
|
tableView.backgroundColor = .systemBackground
|
||||||
|
tableView.contentInset.top = 8
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
subcategories.count
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CategoryCardCell
|
||||||
|
let sub = subcategories[indexPath.row]
|
||||||
|
cell.configure(with: makeSynthetic(sub), color: Theme.Color.category(at: colorIndex))
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
Haptics.selection()
|
||||||
|
let sub = subcategories[indexPath.row]
|
||||||
|
navigationController?.pushViewController(
|
||||||
|
WordListViewController(category: makeSynthetic(sub), colorIndex: colorIndex), animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func makeSynthetic(_ sub: Subcategory) -> WordCategory {
|
||||||
|
WordCategory(id: sub.name, name: sub.name, icon: category.icon,
|
||||||
|
words: sub.words, subcategories: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user