From 3808be265587107c0d58db95ab65832b7b5819f4 Mon Sep 17 00:00:00 2001 From: Mijin Jeon Date: Mon, 1 Oct 2018 15:38:12 +0900 Subject: [PATCH] Refactor: Modify reusing class for header #42 - Modify to set a tableview header: using UITableViewHeaderFooterView,xib file --- .../MartHoliday.xcodeproj/project.pbxproj | 8 +++ .../MartHoliday/Base.lproj/Main.storyboard | 63 +------------------ .../View/HolidayTableViewCell.swift | 16 ----- .../ViewController/DetailViewController.swift | 14 +++-- .../ViewController/MainViewController.swift | 2 +- 5 files changed, 21 insertions(+), 82 deletions(-) diff --git a/MartHoliday/MartHoliday.xcodeproj/project.pbxproj b/MartHoliday/MartHoliday.xcodeproj/project.pbxproj index d64da02..365d332 100644 --- a/MartHoliday/MartHoliday.xcodeproj/project.pbxproj +++ b/MartHoliday/MartHoliday.xcodeproj/project.pbxproj @@ -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 */; }; @@ -173,6 +175,8 @@ FD7BC8D0215620FF002BE5EA /* MapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewController.swift; sourceTree = ""; }; FD7DA865214981DA0070B25B /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; FD80CE202160D70100C16150 /* MartMapDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MartMapDelegate.swift; sourceTree = ""; }; + FD80CE282161241D00C16150 /* DetailHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DetailHeaderView.xib; sourceTree = ""; }; + FD80CE2A21612BAE00C16150 /* HolidayHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HolidayHeaderView.swift; sourceTree = ""; }; 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 = ""; }; @@ -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 */, @@ -403,6 +408,7 @@ FD9F40A2211ECB26007D7F1B /* Utility */, FDAF601A21273D9F0006B68A /* fonts */, FDB4BE25211D6BAD00D3B264 /* Main.storyboard */, + FD80CE282161241D00C16150 /* DetailHeaderView.xib */, FD4850F521287AFE0064747A /* SlideMenuCellView.xib */, FD1B4F242126C0FA00946311 /* SlideMenuView.xib */, FD66C2802158F6F800B4F823 /* MainHeaderView.xib */, @@ -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 */, @@ -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 */, diff --git a/MartHoliday/MartHoliday/Base.lproj/Main.storyboard b/MartHoliday/MartHoliday/Base.lproj/Main.storyboard index 61dade5..50f603a 100644 --- a/MartHoliday/MartHoliday/Base.lproj/Main.storyboard +++ b/MartHoliday/MartHoliday/Base.lproj/Main.storyboard @@ -13,9 +13,6 @@ - - NanumSquareRoundOTFB - NanumSquareRoundOTFR @@ -191,68 +188,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -549,7 +493,6 @@ - diff --git a/MartHoliday/MartHoliday/View/HolidayTableViewCell.swift b/MartHoliday/MartHoliday/View/HolidayTableViewCell.swift index 5cd44b0..b5a69b6 100644 --- a/MartHoliday/MartHoliday/View/HolidayTableViewCell.swift +++ b/MartHoliday/MartHoliday/View/HolidayTableViewCell.swift @@ -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 ?? "정보가 없습니다 :(" - } - -} diff --git a/MartHoliday/MartHoliday/ViewController/DetailViewController.swift b/MartHoliday/MartHoliday/ViewController/DetailViewController.swift index 41d8d2e..d92b2ba 100644 --- a/MartHoliday/MartHoliday/ViewController/DetailViewController.swift +++ b/MartHoliday/MartHoliday/ViewController/DetailViewController.swift @@ -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) { @@ -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() { diff --git a/MartHoliday/MartHoliday/ViewController/MainViewController.swift b/MartHoliday/MartHoliday/ViewController/MainViewController.swift index c2819b7..dc14c5c 100644 --- a/MartHoliday/MartHoliday/ViewController/MainViewController.swift +++ b/MartHoliday/MartHoliday/ViewController/MainViewController.swift @@ -16,6 +16,7 @@ protocol FavoriteConvertible { protocol HeaderDelegate { var favoriteData: [ExpandCollapseTogglable] { get set } func selectHeader(index: Int) + } protocol FooterDelegate { @@ -114,7 +115,6 @@ class MainViewController: UIViewController, FavoriteConvertible, HeaderDelegate, } func toggleFooter(index: Int) { - print("푸터 인덱스 번호: \(index)") favoriteData[index].toggleExpand() tableView.reloadSections([index], with: .automatic) }