From d77f4da2eecf5404447d99b06d0487df0762e2bd Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 21 Jul 2026 21:08:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=89=E5=AD=90=E5=88=86=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=88=AB=E6=94=B9=E4=B8=BA=E9=9D=A2=E6=9D=BF=E5=85=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E7=82=B9=E5=87=BB=E5=90=8E=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E5=AD=90=E5=88=86=E7=B1=BB=E5=88=97=E8=A1=A8=E9=A1=B5=E5=86=8D?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=8D=95=E8=AF=8D=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .../Views/CategoryListViewController.swift | 9 +++- .../Views/SubcategoryListViewController.swift | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 LearnEnglish/LearnEnglish/Views/SubcategoryListViewController.swift diff --git a/LearnEnglish/LearnEnglish/Views/CategoryListViewController.swift b/LearnEnglish/LearnEnglish/Views/CategoryListViewController.swift index fa88a5a..446564b 100644 --- a/LearnEnglish/LearnEnglish/Views/CategoryListViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/CategoryListViewController.swift @@ -53,7 +53,12 @@ final class CategoryListViewController: UITableViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { Haptics.selection() let category = store.categories[indexPath.row] - navigationController?.pushViewController( - WordListViewController(category: category, colorIndex: indexPath.row), animated: true) + if let subs = category.subcategories, !subs.isEmpty { + let vc = SubcategoryListViewController(category: category, colorIndex: indexPath.row) + navigationController?.pushViewController(vc, animated: true) + } else { + navigationController?.pushViewController( + WordListViewController(category: category, colorIndex: indexPath.row), animated: true) + } } } diff --git a/LearnEnglish/LearnEnglish/Views/SubcategoryListViewController.swift b/LearnEnglish/LearnEnglish/Views/SubcategoryListViewController.swift new file mode 100644 index 0000000..fde4d46 --- /dev/null +++ b/LearnEnglish/LearnEnglish/Views/SubcategoryListViewController.swift @@ -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) + } +}