Skip to content

Commit

Permalink
Refactor: Modify reusing class for header #42
Browse files Browse the repository at this point in the history
- Modify to set a tableview header: using UITableViewHeaderFooterView,xib file
  • Loading branch information
jinios committed Oct 1, 2018
1 parent 2cb9c1c commit 3808be2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 82 deletions.
8 changes: 8 additions & 0 deletions MartHoliday/MartHoliday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
FD7BC8D1215620FF002BE5EA /* MapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7BC8D0215620FF002BE5EA /* MapViewController.swift */; };
FD7DA866214981DB0070B25B /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = FD7DA865214981DA0070B25B /* GoogleService-Info.plist */; };
FD80CE212160D70100C16150 /* MartMapDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD80CE202160D70100C16150 /* MartMapDelegate.swift */; };
FD80CE292161241D00C16150 /* DetailHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FD80CE282161241D00C16150 /* DetailHeaderView.xib */; };
FD80CE2B21612BAE00C16150 /* HolidayHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD80CE2A21612BAE00C16150 /* HolidayHeaderView.swift */; };
FD85985B214BE9FA00C1A3E2 /* NotificationCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FD85985A214BE9FA00C1A3E2 /* NotificationCenter.framework */; };
FD85985E214BE9FA00C1A3E2 /* TodayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD85985D214BE9FA00C1A3E2 /* TodayViewController.swift */; };
FD859861214BE9FA00C1A3E2 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FD85985F214BE9FA00C1A3E2 /* MainInterface.storyboard */; };
Expand Down Expand Up @@ -173,6 +175,8 @@
FD7BC8D0215620FF002BE5EA /* MapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewController.swift; sourceTree = "<group>"; };
FD7DA865214981DA0070B25B /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
FD80CE202160D70100C16150 /* MartMapDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MartMapDelegate.swift; sourceTree = "<group>"; };
FD80CE282161241D00C16150 /* DetailHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DetailHeaderView.xib; sourceTree = "<group>"; };
FD80CE2A21612BAE00C16150 /* HolidayHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HolidayHeaderView.swift; sourceTree = "<group>"; };
FD859859214BE9FA00C1A3E2 /* MartHolidayTodayExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = MartHolidayTodayExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
FD85985A214BE9FA00C1A3E2 /* NotificationCenter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NotificationCenter.framework; path = System/Library/Frameworks/NotificationCenter.framework; sourceTree = SDKROOT; };
FD85985D214BE9FA00C1A3E2 /* TodayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -279,6 +283,7 @@
FDF8058221315DC200B22356 /* HolidaysCell.swift */,
FD4DDC8F21412294004E981F /* SelectionTableViewCell.swift */,
FD5E63F82153C8F400DC082A /* HolidayTableViewCell.swift */,
FD80CE2A21612BAE00C16150 /* HolidayHeaderView.swift */,
FD66C2822158FD7700B4F823 /* MainTableViewFooter.swift */,
FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */,
FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */,
Expand Down Expand Up @@ -403,6 +408,7 @@
FD9F40A2211ECB26007D7F1B /* Utility */,
FDAF601A21273D9F0006B68A /* fonts */,
FDB4BE25211D6BAD00D3B264 /* Main.storyboard */,
FD80CE282161241D00C16150 /* DetailHeaderView.xib */,
FD4850F521287AFE0064747A /* SlideMenuCellView.xib */,
FD1B4F242126C0FA00946311 /* SlideMenuView.xib */,
FD66C2802158F6F800B4F823 /* MainHeaderView.xib */,
Expand Down Expand Up @@ -568,6 +574,7 @@
FDAF602121273E880006B68A /* NanumSquareRoundOTFR.otf in Resources */,
FDB4BE2C211D6BAE00D3B264 /* LaunchScreen.storyboard in Resources */,
FD52566F21353C9C0014070E /* KeyInfo.plist in Resources */,
FD80CE292161241D00C16150 /* DetailHeaderView.xib in Resources */,
FDAF601F21273E880006B68A /* NanumSquareRoundOTFL.otf in Resources */,
FDB4BE29211D6BAE00D3B264 /* Assets.xcassets in Resources */,
FDB4BE27211D6BAD00D3B264 /* Main.storyboard in Resources */,
Expand Down Expand Up @@ -703,6 +710,7 @@
FDBF9A4821240911001C2DAA /* DataStorage.swift in Sources */,
FD1B4F212126BB8B00946311 /* SlideBackgroundView.swift in Sources */,
FD9F40A0211EC5EA007D7F1B /* Keywords.swift in Sources */,
FD80CE2B21612BAE00C16150 /* HolidayHeaderView.swift in Sources */,
FDC3461D2136708400F6D6FF /* AddressDatum.swift in Sources */,
FDB4BE24211D6BAD00D3B264 /* MartSelectViewController.swift in Sources */,
FDF8ABC4215B76B400DA74C9 /* MainTableViewHeader.swift in Sources */,
Expand Down
63 changes: 3 additions & 60 deletions MartHoliday/MartHoliday/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="NanumSquareRoundOTFB.otf">
<string>NanumSquareRoundOTFB</string>
</array>
<array key="NanumSquareRoundOTFR.otf">
<string>NanumSquareRoundOTFR</string>
</array>
Expand Down Expand Up @@ -191,68 +188,15 @@
<constraint firstAttribute="height" constant="200" id="FKq-BY-EwQ"/>
</constraints>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="headerCell" rowHeight="80" id="wn9-Ah-iwn" customClass="HolidayHeaderCell" customModule="MartHoliday" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="wn9-Ah-iwn" id="YbA-af-8Kc">
<rect key="frame" x="0.0" y="0.0" width="375" height="79.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nFc-YE-hkV">
<rect key="frame" x="330" y="29" width="20" height="22"/>
<state key="normal" image="downArrow"/>
<connections>
<action selector="moreButtonTapped:" destination="wn9-Ah-iwn" eventType="touchUpInside" id="h2Q-DQ-d15"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZoB-x9-mqp">
<rect key="frame" x="20" y="40" width="205" height="21"/>
<fontDescription key="fontDescription" name="NanumSquareRoundOTFB" family="NanumSquareRoundOTF" pointSize="19"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="휴무일" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dRF-S3-WpA">
<rect key="frame" x="20" y="11" width="90" height="18"/>
<fontDescription key="fontDescription" name="NanumSquareRoundOTFR" family="NanumSquareRoundOTF" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xvL-3C-bCy" userLabel="belowBar">
<rect key="frame" x="18.5" y="69" width="337" height="1"/>
<color key="backgroundColor" red="0.81960784310000001" green="0.81960784310000001" blue="0.83921568629999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="CCg-X1-iS3"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstItem="dRF-S3-WpA" firstAttribute="top" secondItem="YbA-af-8Kc" secondAttribute="topMargin" id="0lk-Qj-LcE"/>
<constraint firstItem="xvL-3C-bCy" firstAttribute="width" secondItem="YbA-af-8Kc" secondAttribute="width" multiplier="0.9" id="3ZP-yy-Qeg"/>
<constraint firstAttribute="trailingMargin" relation="lessThanOrEqual" secondItem="dRF-S3-WpA" secondAttribute="trailing" constant="250" id="DHQ-1R-ELl"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="ZoB-x9-mqp" secondAttribute="trailing" constant="150" id="GFz-xn-zZi"/>
<constraint firstAttribute="bottomMargin" secondItem="nFc-YE-hkV" secondAttribute="bottom" constant="18" id="N1K-w8-7Ny"/>
<constraint firstItem="nFc-YE-hkV" firstAttribute="top" secondItem="YbA-af-8Kc" secondAttribute="topMargin" constant="18" id="OFD-Qd-G0g"/>
<constraint firstItem="xvL-3C-bCy" firstAttribute="centerX" secondItem="YbA-af-8Kc" secondAttribute="centerX" id="Y49-F9-JuJ"/>
<constraint firstItem="xvL-3C-bCy" firstAttribute="top" secondItem="ZoB-x9-mqp" secondAttribute="bottom" constant="8" id="hMe-ed-TqY"/>
<constraint firstItem="ZoB-x9-mqp" firstAttribute="leading" secondItem="YbA-af-8Kc" secondAttribute="leadingMargin" constant="5" id="kVC-u3-hPS"/>
<constraint firstAttribute="trailingMargin" secondItem="nFc-YE-hkV" secondAttribute="trailing" constant="10" id="qxn-hN-agq"/>
<constraint firstItem="dRF-S3-WpA" firstAttribute="leading" secondItem="YbA-af-8Kc" secondAttribute="leadingMargin" constant="5" id="wqw-xS-WeY"/>
<constraint firstItem="ZoB-x9-mqp" firstAttribute="top" secondItem="dRF-S3-WpA" secondAttribute="bottom" constant="11" id="yXJ-hH-UUg"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="dateLabel" destination="ZoB-x9-mqp" id="X7g-cN-C7m"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="dateCell" rowHeight="35" id="ppU-sH-JYg" customClass="HolidayTableViewCell" customModule="MartHoliday" customModuleProvider="target">
<rect key="frame" x="0.0" y="108" width="375" height="35"/>
<rect key="frame" x="0.0" y="28" width="375" height="35"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ppU-sH-JYg" id="l3J-Mw-sST">
<rect key="frame" x="0.0" y="0.0" width="375" height="34.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fM5-h6-WFW">
<rect key="frame" x="20" y="8" width="205" height="19"/>
<rect key="frame" x="30" y="8" width="195" height="19"/>
<fontDescription key="fontDescription" name="NanumSquareRoundOTFR" family="NanumSquareRoundOTF" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand All @@ -261,7 +205,7 @@
<constraints>
<constraint firstAttribute="trailingMargin" relation="lessThanOrEqual" secondItem="fM5-h6-WFW" secondAttribute="trailing" constant="135" id="CNH-NB-3JJ"/>
<constraint firstItem="fM5-h6-WFW" firstAttribute="centerY" secondItem="l3J-Mw-sST" secondAttribute="centerY" id="fc8-0o-tdQ"/>
<constraint firstItem="fM5-h6-WFW" firstAttribute="leading" secondItem="l3J-Mw-sST" secondAttribute="leadingMargin" constant="5" id="jwa-qb-GAG"/>
<constraint firstItem="fM5-h6-WFW" firstAttribute="leading" secondItem="l3J-Mw-sST" secondAttribute="leading" constant="30" id="jwa-qb-GAG"/>
</constraints>
</tableViewCellContentView>
<connections>
Expand Down Expand Up @@ -549,7 +493,6 @@
</scenes>
<resources>
<image name="call-circle" width="40" height="40"/>
<image name="downArrow" width="20" height="20"/>
<image name="emptyStar" width="64" height="64"/>
<image name="safari-circle" width="40" height="40"/>
<image name="star" width="40" height="40"/>
Expand Down
16 changes: 0 additions & 16 deletions MartHoliday/MartHoliday/View/HolidayTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,3 @@ class HolidayTableViewCell: UITableViewCell {
}

}


class HolidayHeaderCell: UITableViewCell {

@IBOutlet weak var dateLabel: UILabel!
var delegate: DetailHeaderDelegate?

@IBAction func moreButtonTapped(_ sender: Any) {
delegate?.toggleHeader()
}

func set(holiday: String?) {
dateLabel.text = holiday ?? "정보가 없습니다 :("
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class DetailViewController: UIViewController, SFSafariViewControllerDelegate, Ma
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .none
tableView.register(UINib(nibName: "DetailHeaderView", bundle: nil),forHeaderFooterViewReuseIdentifier: "detailHeader")

}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -231,13 +233,15 @@ extension DetailViewController: UITableViewDelegate, UITableViewDataSource, Deta
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let branchData = branchData else { return UIView() }
let view = tableView.dequeueReusableCell(withIdentifier: "headerCell") as! HolidayHeaderCell
guard let branchData = branchData else { return nil }
guard let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "detailHeader") as? HolidayHeaderView else { return nil }
view.delegate = self
view.set(holiday: branchData.holidays.isEmpty ? nil:branchData.holidays[0])
let contentView = view.contentView
contentView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapHeader)))
return contentView

let state = self.isExpanded
view.setExpand(state: state)

return view
}

@objc func tapHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol FavoriteConvertible {
protocol HeaderDelegate {
var favoriteData: [ExpandCollapseTogglable] { get set }
func selectHeader(index: Int)

}

protocol FooterDelegate {
Expand Down Expand Up @@ -114,7 +115,6 @@ class MainViewController: UIViewController, FavoriteConvertible, HeaderDelegate,
}

func toggleFooter(index: Int) {
print("푸터 인덱스 번호: \(index)")
favoriteData[index].toggleExpand()
tableView.reloadSections([index], with: .automatic)
}
Expand Down

0 comments on commit 3808be2

Please sign in to comment.