Skip to content

Commit 7cd5d17

Browse files
committed
✨ [feat] 신고 리스트 tableView 구현
1 parent 83087a4 commit 7cd5d17

File tree

2 files changed

+144
-2
lines changed

2 files changed

+144
-2
lines changed

Fitfty/Projects/Setting/Sources/Admin/VewController/ReportListViewController.swift

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ final public class ReportListViewController: UIViewController {
1414
private let menuView = ReportMenuView()
1515
private var coordinator: ReportListCoordinatorInterface
1616

17+
private lazy var tableView: UITableView = {
18+
let tableView = UITableView()
19+
tableView.register(ReportListCell.self, forCellReuseIdentifier: ReportListCell.className)
20+
tableView.delegate = self
21+
tableView.separatorInset = .init(top: .zero, left: .zero, bottom: .zero, right: .zero)
22+
return tableView
23+
}()
24+
25+
private var dataSource: UITableViewDiffableDataSource<ReportListSectionKind, ReportListCellModel>?
26+
1727
public init(coordinator: ReportListCoordinatorInterface) {
1828
self.coordinator = coordinator
1929
super.init(nibName: nil, bundle: nil)
@@ -31,6 +41,10 @@ final public class ReportListViewController: UIViewController {
3141
private func setUp() {
3242
setConstraintsLayout()
3343
setNavigationBar()
44+
setDataSource()
45+
applySnapshot([
46+
ReportListSection(sectionKind: .report, items: [ReportListCellModel.report("a", true), ReportListCellModel.report("aa", true)])
47+
])
3448
}
3549

3650
@objc func didTapBackButton(_ sender: Any?) {
@@ -42,12 +56,16 @@ final public class ReportListViewController: UIViewController {
4256
private extension ReportListViewController {
4357

4458
func setConstraintsLayout() {
45-
view.addSubviews(menuView)
59+
view.addSubviews(menuView, tableView)
4660
NSLayoutConstraint.activate([
4761
menuView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 5),
4862
menuView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
4963
menuView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
50-
menuView.heightAnchor.constraint(equalToConstant: 20)
64+
menuView.heightAnchor.constraint(equalToConstant: 20),
65+
tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
66+
tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20),
67+
tableView.topAnchor.constraint(equalTo: menuView.bottomAnchor, constant: 10),
68+
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
5169
])
5270
}
5371

@@ -64,4 +82,33 @@ private extension ReportListViewController {
6482
navigationItem.leftBarButtonItem = cancelButton
6583
}
6684

85+
func setDataSource() {
86+
dataSource = UITableViewDiffableDataSource<ReportListSectionKind, ReportListCellModel>(
87+
tableView: tableView, cellProvider: { tableView, indexPath, item in
88+
switch item {
89+
case .report(let title, let isSelected):
90+
let cell = tableView.dequeueReusableCell(withIdentifier: ReportListCell.className, for: indexPath) as? ReportListCell
91+
cell?.selectionStyle = .none
92+
return cell
93+
}
94+
})
95+
}
96+
97+
func applySnapshot(_ sections: [ReportListSection]) {
98+
var snapshot = NSDiffableDataSourceSnapshot<ReportListSectionKind, ReportListCellModel>()
99+
sections.forEach {
100+
snapshot.appendSections([$0.sectionKind])
101+
snapshot.appendItems($0.items)
102+
}
103+
dataSource?.apply(snapshot, animatingDifferences: false)
104+
}
105+
106+
}
107+
108+
extension ReportListViewController: UITableViewDelegate {
109+
110+
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
111+
return 44
112+
}
113+
67114
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// ReportListCell.swift
3+
// Setting
4+
//
5+
// Created by 임영선 on 2023/02/16.
6+
// Copyright © 2023 Fitfty. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import Common
11+
12+
final class ReportListCell: UITableViewCell {
13+
14+
private lazy var checkBoxButton: UIButton = {
15+
let button = UIButton()
16+
button.setImage(CommonAsset.Images.btnCheckBoxUnSelected.image, for: .normal)
17+
button.isUserInteractionEnabled = false
18+
button.addTarget(self, action: #selector(didTapCheckbox), for: .touchUpInside)
19+
return button
20+
}()
21+
22+
private lazy var accountLabel: UILabel = {
23+
let label = UILabel()
24+
label.textColor = CommonAsset.Colors.gray06.color
25+
label.font = FitftyFont.appleSDMedium(size: 15).font
26+
label.text = "[email protected]"
27+
return label
28+
}()
29+
30+
private lazy var detailReportLabel: UILabel = {
31+
let label = UILabel()
32+
label.textColor = CommonAsset.Colors.gray06.color
33+
label.font = FitftyFont.appleSDMedium(size: 15).font
34+
label.text = "불쾌"
35+
return label
36+
}()
37+
38+
private lazy var countLabel: UILabel = {
39+
let label = UILabel()
40+
label.textColor = CommonAsset.Colors.gray06.color
41+
label.font = FitftyFont.appleSDMedium(size: 15).font
42+
label.text = "13"
43+
return label
44+
}()
45+
46+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
47+
super.init(style: style, reuseIdentifier: reuseIdentifier)
48+
setConstraintsLayout()
49+
}
50+
51+
required init(coder: NSCoder) {
52+
fatalError("init(coder:) has not been implemented")
53+
}
54+
55+
private func setConstraintsLayout() {
56+
addSubviews(checkBoxButton, accountLabel, detailReportLabel, countLabel)
57+
NSLayoutConstraint.activate([
58+
checkBoxButton.centerYAnchor.constraint(equalTo: centerYAnchor),
59+
checkBoxButton.widthAnchor.constraint(equalToConstant: 20),
60+
checkBoxButton.heightAnchor.constraint(equalToConstant: 20),
61+
checkBoxButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
62+
63+
accountLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
64+
accountLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
65+
accountLabel.widthAnchor.constraint(equalToConstant: 120),
66+
67+
detailReportLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
68+
detailReportLabel.leadingAnchor.constraint(equalTo: accountLabel.trailingAnchor, constant: 10),
69+
detailReportLabel.widthAnchor.constraint(equalToConstant: 120),
70+
71+
countLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
72+
countLabel.leadingAnchor.constraint(equalTo: detailReportLabel.trailingAnchor, constant: 10),
73+
countLabel.widthAnchor.constraint(equalToConstant: 50)
74+
])
75+
}
76+
77+
@objc func didTapCheckbox(_ sender: Any?) {
78+
if !checkBoxButton.isSelected {
79+
checkBoxButton.setImage(CommonAsset.Images.btnCheckBoxSelected.image, for: .normal)
80+
} else {
81+
checkBoxButton.setImage(CommonAsset.Images.btnCheckBoxUnSelected.image, for: .normal)
82+
}
83+
}
84+
85+
}
86+
87+
extension ReportListCell {
88+
89+
func setUp(account: String, detailReport: String, count: String) {
90+
accountLabel.text = account
91+
detailReportLabel.text = detailReport
92+
countLabel.text = count
93+
}
94+
95+
}

0 commit comments

Comments
 (0)