Skip to content

Commit

Permalink
[#12] Main 화면 테이블뷰로 재작성
Browse files Browse the repository at this point in the history
  • Loading branch information
chongin12 committed Dec 31, 2024
1 parent 6577fbe commit 67e7634
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Handy/Handy-Storybook/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: UIScreen.main.bounds)
window?.windowScene = windowScene
window?.rootViewController = TabsViewController()
window?.rootViewController = UINavigationController(rootViewController: MainViewController())
window?.makeKeyAndVisible()
}

Expand Down
87 changes: 87 additions & 0 deletions Handy/Handy-Storybook/Storybook/MainViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// MainViewController.swift
// Handy
//
// Created by chongin on 12/31/24.
//

import UIKit

class MainViewController: UITableViewController {

private let components: [HandyStorybookComponent] = [
.init(("SnackbarViewController", SnackbarViewController())),
.init(("LabelViewController", LabelViewController())),
.init(("FabViewController", FabViewController())),
.init(("HandyBoxButtonViewController", HandyBoxButtonViewController())),
.init(("ChipViewController", ChipViewController())),
.init(("DividerViewController", DividerViewController())),
.init(("CheckBoxViewController", CheckBoxViewController())),
.init(("RadioButtonViewController", RadioButtonViewController())),
.init(("HansySwitchViewController", HansySwitchViewController())),
.init(("TabsViewController", TabsViewController())),
]

override func viewDidLoad() {
super.viewDidLoad()

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
}
}

extension MainViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return components.count
default:
return 0
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let component = components[indexPath.row]
cell.textLabel?.text = component.title
return cell
default:
fatalError()
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 0:
let component = components[indexPath.row]
navigationController?.pushViewController(component.viewController, animated: true)
default:
fatalError()
}
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return "Components"
default:
fatalError()
}
}
}

struct HandyStorybookComponent {
let title: String
let viewController: UIViewController

init(title: String, viewController: UIViewController) {
self.title = title
self.viewController = viewController
}

init<VC: UIViewController>(_ component: (title: String, viewController: VC)) {
self.title = component.title
self.viewController = component.viewController as UIViewController
}
}
4 changes: 4 additions & 0 deletions Handy/Handy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
6FD1A1802D213129001E6F2E /* TabsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */; };
6FE73E942D23C52F00E06422 /* HandyTabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E932D23C52C00E06422 /* HandyTabs.swift */; };
6FE73E962D23C55900E06422 /* HandyTabComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E952D23C55900E06422 /* HandyTabComponent.swift */; };
6FE73E982D23D7A900E06422 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E972D23D6E500E06422 /* MainViewController.swift */; };
A56B3DE22C4E51D300C3610A /* HandyChip.swift in Sources */ = {isa = PBXBuildFile; fileRef = A56B3DE12C4E51D300C3610A /* HandyChip.swift */; };
A5A12A7E2C57A6D900996916 /* ChipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5A12A7C2C57A6C200996916 /* ChipViewController.swift */; };
A5A12A7F2C57A92000996916 /* HandySematic.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5D02AFC2C46C5A70056CE7B /* HandySematic.swift */; };
Expand Down Expand Up @@ -121,6 +122,7 @@
6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsViewController.swift; sourceTree = "<group>"; };
6FE73E932D23C52C00E06422 /* HandyTabs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyTabs.swift; sourceTree = "<group>"; };
6FE73E952D23C55900E06422 /* HandyTabComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyTabComponent.swift; sourceTree = "<group>"; };
6FE73E972D23D6E500E06422 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
A56B3DE12C4E51D300C3610A /* HandyChip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyChip.swift; sourceTree = "<group>"; };
A5A12A7C2C57A6C200996916 /* ChipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipViewController.swift; sourceTree = "<group>"; };
A5F6D36A2C96F32D00FB961F /* HandyDivider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyDivider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -208,6 +210,7 @@
0257765A2C4EB9B800272EC6 /* Storybook */ = {
isa = PBXGroup;
children = (
6FE73E972D23D6E500E06422 /* MainViewController.swift */,
0257763F2C4EA98E00272EC6 /* LaunchScreen.storyboard */,
0257765B2C4EB9C700272EC6 /* Base */,
);
Expand Down Expand Up @@ -479,6 +482,7 @@
A5A12A7E2C57A6D900996916 /* ChipViewController.swift in Sources */,
A5A12A7F2C57A92000996916 /* HandySematic.swift in Sources */,
A5F6D36D2C97099C00FB961F /* DividerViewController.swift in Sources */,
6FE73E982D23D7A900E06422 /* MainViewController.swift in Sources */,
025776392C4EA98C00272EC6 /* LabelViewController.swift in Sources */,
0257765D2C4EB9EF00272EC6 /* BaseViewController.swift in Sources */,
02ED764C2C57BD09001569F1 /* HandyBoxButtonViewController.swift in Sources */,
Expand Down

0 comments on commit 67e7634

Please sign in to comment.