Skip to content

Commit

Permalink
[#330] Refactor TableViewTemplateVC to use BaseTableViewVC
Browse files Browse the repository at this point in the history
Additional clean up.
  • Loading branch information
damien-rivet committed Dec 15, 2023
1 parent 2bed3f1 commit 26a22b8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 103 deletions.
1 change: 0 additions & 1 deletion Scribe/AboutTab/InformationScreenVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class InformationScreenVC: UIViewController {
@IBOutlet var iconImageView: UIImageView!

var text: String = ""
var screenTitle: String = ""
var section: SectionState = .privacyPolicy

override func viewDidLoad() {
Expand Down
51 changes: 20 additions & 31 deletions Scribe/Base.lproj/AppScreen.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -219,43 +219,13 @@
<outlet property="footerButton" destination="3gB-ix-8Gq" id="sQ7-oh-pis"/>
<outlet property="footerFrame" destination="IUx-l8-ZuO" id="zei-iv-IbX"/>
<outlet property="parentTable" destination="R98-aa-uZS" id="5wJ-1H-Zp2"/>
<segue destination="4YA-bx-fdf" kind="show" id="ZXJ-g2-Dsn"/>
<segue destination="ZA3-mW-CXa" kind="show" id="WZJ-vL-yPU"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="I0c-Lq-Rf5" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-888.79999999999995" y="-100.49261083743843"/>
</scene>
<!--Table View Template View Controller-->
<scene sceneID="sI7-t7-s2m">
<objects>
<viewController storyboardIdentifier="TableViewTemplateViewController" id="4YA-bx-fdf" customClass="TableViewTemplateViewController" customModule="Scribe" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="PBQ-hz-8QI">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="insetGrouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" estimatedSectionHeaderHeight="-1" sectionFooterHeight="18" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="obq-rY-JVB">
<rect key="frame" x="0.0" y="154" width="375" height="575"/>
</tableView>
</subviews>
<viewLayoutGuide key="safeArea" id="SyY-44-GGu"/>
<color key="backgroundColor" name="scribeAppBackground"/>
<constraints>
<constraint firstItem="obq-rY-JVB" firstAttribute="top" secondItem="SyY-44-GGu" secondAttribute="top" constant="8" id="SV4-gG-JiQ"/>
<constraint firstItem="SyY-44-GGu" firstAttribute="bottom" secondItem="obq-rY-JVB" secondAttribute="bottom" id="dlD-Aa-HJd"/>
<constraint firstItem="SyY-44-GGu" firstAttribute="trailing" secondItem="obq-rY-JVB" secondAttribute="trailing" id="hNo-Oc-OMY"/>
<constraint firstItem="obq-rY-JVB" firstAttribute="leading" secondItem="SyY-44-GGu" secondAttribute="leading" id="nvD-tt-zHX"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="YW1-CT-vgn"/>
<connections>
<outlet property="mainTable" destination="obq-rY-JVB" id="Qbh-ZZ-2ho"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="RRR-Nu-rPx" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="25" y="-100"/>
</scene>
<!--Swipeable Tab Bar Controller-->
<scene sceneID="sLs-HO-3by">
<objects>
Expand Down Expand Up @@ -434,6 +404,25 @@
</objects>
<point key="canvasLocation" x="-1831.2" y="-100.49261083743843"/>
</scene>
<!--Table View Template View Controller-->
<scene sceneID="okZ-mS-Z02">
<objects>
<tableViewController storyboardIdentifier="TableViewTemplateViewController" id="ZA3-mW-CXa" customClass="TableViewTemplateViewController" customModule="Scribe" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="insetGrouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" estimatedSectionHeaderHeight="-1" sectionFooterHeight="18" estimatedSectionFooterHeight="-1" id="AcG-ai-d5x">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="scribeAppBackground"/>
<connections>
<outlet property="dataSource" destination="ZA3-mW-CXa" id="LpK-sh-yHG"/>
<outlet property="delegate" destination="ZA3-mW-CXa" id="6TP-eq-rrB"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="vhy-kK-VNo"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="AWg-K9-pJG" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="25" y="-100"/>
</scene>
</scenes>
<color key="tintColor" name="scribeAppBackground"/>
<resources>
Expand Down
91 changes: 30 additions & 61 deletions Scribe/Components/TableViewTemplateViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,57 @@

import UIKit

final class TableViewTemplateViewController: UIViewController {
@IBOutlet var mainTable: UITableView!
final class TableViewTemplateViewController: BaseTableViewController {

var screenTitle: String = ""
var tableData: [ParentTableCellModel] = []
var parentSection: Section?
// MARK: - Properties

var langCode: String {
if let section = parentSection {
guard case let .specificLang(lang) = section.sectionState else { return "de" }
override var dataSet: [ParentTableCellModel] {
tableData
}

private var tableData: [ParentTableCellModel] = []
private var parentSection: Section?

return lang
private var langCode: String {
guard let parentSection else {
return ""
}

return ""
}
guard case let .specificLang(lang) = parentSection.sectionState else {
return "de"
}

func configureTable(for tableData: [ParentTableCellModel], parentSection: Section) {
self.tableData = tableData
self.parentSection = parentSection
return lang
}

// MARK: - Functions

override func viewDidLoad() {
super.viewDidLoad()

title = parentSection?.sectionTitle ?? "Unknown"

mainTable.register(UINib(nibName: "InfoChildTableViewCell", bundle: nil), forCellReuseIdentifier: "InfoChildTableViewCell")
mainTable.dataSource = self
mainTable.delegate = self
mainTable.rowHeight = UITableView.automaticDimension
mainTable.sectionHeaderHeight = 32
mainTable.estimatedRowHeight = 250
mainTable.separatorStyle = .none
mainTable.backgroundColor = .clear
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 250
tableView.separatorStyle = .none
}
}

// MARK: - UITableViewDataSource

extension TableViewTemplateViewController: UITableViewDataSource {
func configureTable(for tableData: [ParentTableCellModel], parentSection: Section) {
self.tableData = tableData
self.parentSection = parentSection

func numberOfSections(in tableView: UITableView) -> Int {
tableData.count
title = parentSection.sectionTitle
}
}

func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
tableData[section].section.count
}
// MARK: - UITableViewDataSource

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "InfoChildTableViewCell", for: indexPath) as! InfoChildTableViewCell
extension TableViewTemplateViewController {

if let parentSection = parentSection {
cell.parentSection = parentSection
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: InfoChildTableViewCell.reuseIdentifier, for: indexPath) as! InfoChildTableViewCell

cell.parentSection = parentSection
cell.configureCell(for: tableData[indexPath.section].section[indexPath.row])

return cell
}
}

// MARK: - UITableViewDelegate

extension TableViewTemplateViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView: UIView

if let reusableHeaderView = tableView.headerView(forSection: section) {
headerView = reusableHeaderView
} else {
headerView = UIView(frame: CGRect(x: 0, y: 0, width: mainTable.bounds.width, height: 32))
}

let label = UILabel(frame: CGRect(x: 0, y: 0, width: headerView.bounds.width, height: 32))
label.text = tableData[section].headingTitle
label.font = UIFont.preferredFont(forTextStyle: .headline)
label.textColor = .black
headerView.addSubview(label)

return headerView
}
}
10 changes: 0 additions & 10 deletions Scribe/Views/BaseTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ class BaseTableViewController: UITableViewController {
[]
}

// MARK: - Initialisation

override init(style: UITableView.Style) {
super.init(style: .insetGrouped)
}

required init?(coder: NSCoder) {
super.init(coder: coder)
}

// MARK: - Functions

override func viewDidLoad() {
Expand Down

0 comments on commit 26a22b8

Please sign in to comment.