-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from boostcamp3-iOS/feature/scrapView_59
Feature/scrap view 59
- Loading branch information
Showing
13 changed files
with
498 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tree/tree/Controller/Scrap/ScrapFilterViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// ScrapFilterViewController.swift | ||
// tree | ||
// | ||
// Created by Hyeontae on 05/02/2019. | ||
// Copyright © 2019 gardener. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ScrapFilterViewController: UIViewController { | ||
|
||
@IBOutlet weak var headerView: UIView! | ||
@IBOutlet weak var headerTitleLabel: UILabel! | ||
@IBOutlet weak var tableView: UITableView! | ||
|
||
private let cellIdentifier = "ScrapFilterTableViewCell" | ||
private lazy var categories: [ArticleCategory] = { | ||
ArticleCategory.allCases.filter({ | ||
if $0 == .all { return true } | ||
return ScrapManager.countArticle(category: $0, nil) != 0 | ||
}) | ||
}() | ||
weak var filterDelegate: ScrapFilterDelegate? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
tableViewSetup() | ||
} | ||
|
||
private func tableViewSetup() { | ||
tableView.delegate = self | ||
tableView.dataSource = self | ||
tableView.register( | ||
UINib(nibName: cellIdentifier, bundle: nil), | ||
forCellReuseIdentifier: cellIdentifier) | ||
tableView.separatorStyle = .none | ||
} | ||
} | ||
|
||
extension ScrapFilterViewController: UITableViewDataSource, UITableViewDelegate { | ||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return categories.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
guard let cell = | ||
tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) | ||
as? ScrapFilterTableViewCell else { | ||
return UITableViewCell() | ||
} | ||
if indexPath.row == 0 { | ||
cell.setAllCategory(width: view.bounds.width - 32) | ||
} else { | ||
cell.configure(categories[indexPath.row], width: view.bounds.width - 32) | ||
} | ||
return cell | ||
} | ||
|
||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
filterDelegate?.filterArticles(categories[indexPath.row]) | ||
dismiss(animated: true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// ScrapFilterDelegate.swift | ||
// tree | ||
// | ||
// Created by Hyeontae on 09/02/2019. | ||
// Copyright © 2019 gardener. All rights reserved. | ||
// | ||
|
||
protocol ScrapFilterDelegate: class { | ||
func filterArticles(_ article: ArticleCategory) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.