Skip to content

Commit

Permalink
Merge pull request #105 from Jae-eun/feedback
Browse files Browse the repository at this point in the history
FeedbackListVC 수정
  • Loading branch information
presto95 authored Feb 11, 2019
2 parents e8d956c + 7bf6d0c commit 165216f
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 54 deletions.
40 changes: 40 additions & 0 deletions FineDust.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

66 changes: 48 additions & 18 deletions FineDust/Feedback/Controller/FeedbackListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import UIKit
/// 3번째 탭 피드백 화면
final class FeedbackListViewController: UIViewController {

// MARK: IBOutlet
// MARK: - IBOutlet

@IBOutlet private weak var feedbackListTableView: UITableView!

// MARK: Properties
// MARK: - Properties

let jsonManager = JSONManager()
private var dustFeedbacks: [DustFeedbacks] = []
private let reuseIdentifiers = ["recommendTableCell", "feedbackListCell"]
private var count = 10

Expand All @@ -28,16 +26,23 @@ final class FeedbackListViewController: UIViewController {
super.viewDidLoad()
navigationItem.title = "먼지 정보".localized

dustFeedbacks = jsonManager.requestDustFeedbacks()

feedbackListTableView.reloadData()
}

// MARK: - Function

/// 화면 이동
func changeView() {
if let view = self.storyboard?.instantiateViewController(withIdentifier: "DetailView") {
self.navigationController?.pushViewController(view, animated: true)
}
}
}

// MARK: - UITabelViewDataSource

extension FeedbackListViewController: UITableViewDataSource {

func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
Expand All @@ -47,15 +52,18 @@ extension FeedbackListViewController: UITableViewDataSource {
if section == 0 {
return 1
} else {
return count
return 3
}
}

func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView
guard let cell = tableView
.dequeueReusableCell(withIdentifier: reuseIdentifiers[indexPath.section],
for: indexPath)
for: indexPath) as? FeedbackListTableViewCell
else { return UITableViewCell() }

cell.setTabelViewCellProperties(at: indexPath.row)

return cell
}
Expand All @@ -64,20 +72,33 @@ extension FeedbackListViewController: UITableViewDataSource {
// MARK: - UITableViewDelegate

extension FeedbackListViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat {
return 300
}

/// 테이블뷰 헤더 이름 설정.
func tableView(_ tableView: UITableView,
titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "추천"
heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
return 330
} else {
return "목록"
return 130
}
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
changeView()
tableView.deselectRow(at: indexPath, animated: true)
}

}

/// 테이블뷰 헤더 이름 설정.
func tableView(_ tableView: UITableView,
titleForHeaderInSection section: Int) -> String? {

if section == 0 {
return "추천"
} else {
return "목록"
}

}

// MARK: - UICollectionViewDataSource
Expand All @@ -101,6 +122,15 @@ extension FeedbackListViewController: UICollectionViewDataSource {
) as? RecommendCollectionViewCell
else { return UICollectionViewCell() }

cell.setCollectionViewCellProperties(at: indexPath.item)
return cell
}
}

// MARK: - UICollectionViewDelegate

extension FeedbackListViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
changeView()
}
}
26 changes: 25 additions & 1 deletion FineDust/Feedback/FeedbackService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@

import Foundation

/// FeedbackService를 구현하는 클래스 (미완)
final class FeedbackService {

let jsonManager: JSONManagerType?


fileprivate var dustFeedbacks: [DustFeedbacks] = []
var result: [String] = []
init(jsonManager: JSONManagerType) {
self.jsonManager = jsonManager
dustFeedbacks = jsonManager.fetchDustFeedbacks()
}

// func fetchImageName() -> [String] {
// for i in 0..<dustFeedbacks.count {
// result.append(dustFeedbacks[i].imageName)
// }
// return result
// }
//
// func fetchTitle() -> [String] {
// for i in 0..<dustFeedbacks.count {
// result.append(dustFeedbacks[i].title)
// }
// return result
// }
//
// func fetchSource() -> [String] {
// for i in 0..<dustFeedbacks.count {
// result.append(dustFeedbacks[i].source)
// }
// return result
// }
}
53 changes: 27 additions & 26 deletions FineDust/Feedback/View/Feedback.storyboard

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions FineDust/Feedback/View/FeedbackListTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,31 @@ final class FeedbackListTableViewCell: UITableViewCell {

let jsonManager = JSONManager()
fileprivate var dustFeedbacks: [DustFeedbacks] = []
/// 테이블뷰셀 데이터 및 UI 설정

override func awakeFromNib() {
super.awakeFromNib()
setImageView()
}

override func prepareForReuse() {
super.prepareForReuse()
feedbackImageView.image = nil
feedbackTitleLabel.text = nil
feedbackSourceLabel.text = nil
}

/// 테이블뷰셀 데이터 설정
func setTabelViewCellProperties(at index: Int) {
dustFeedbacks = jsonManager.fetchDustFeedbacks()

feedbackImageView.image = UIImage(named: dustFeedbacks[index].imageName)
feedbackTitleLabel.text = dustFeedbacks[index].title
feedbackSourceLabel.text = dustFeedbacks[index].source

}

/// 테이블뷰셀 이미지 UI 설정
func setImageView() {
feedbackImageView.setRounded()

}
}
15 changes: 8 additions & 7 deletions FineDust/Feedback/View/RecommendCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ final class RecommendCollectionViewCell: UICollectionViewCell {
setImageView()
}

/// 셀 데이터 및 UI 설정
override func prepareForReuse() {
super.prepareForReuse()
recommendImageView.image = nil
recommendTitleLabel.text = nil
}

/// 컬렉션뷰셀 데이터 설정
func setCollectionViewCellProperties(at index: Int) {
dustFeedbacks = jsonManager.fetchDustFeedbacks()

recommendImageView.image = UIImage(named: dustFeedbacks[index].imageName )
recommendTitleLabel.text = dustFeedbacks[index].title
}

/// 컬렉션뷰셀 이미지 UI 설정
func setImageView() {
recommendImageView.layer.cornerRadius = 5
recommendImageView.layer.masksToBounds = true
}

override func prepareForReuse() {
super.prepareForReuse()
recommendImageView.image = nil
recommendTitleLabel.text = nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "sort.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 165216f

Please sign in to comment.