Skip to content

Commit

Permalink
[Fix]#10 - 오잉
Browse files Browse the repository at this point in the history
  • Loading branch information
ena-isme committed Dec 12, 2023
1 parent 3d5f4c9 commit 1c3e4a6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,63 +160,63 @@ extension ListViewController: UIPageViewControllerDataSource, UIPageViewControll


//// MARK: - UISearchBarDelegate
//extension ListViewController: UISearchBarDelegate {
// func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
// print("cancel")
// rootView.listWeatherSearchBar.searchTextField.text = ""
// rootView.endEditing(true)
// }
//
// func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
// print("눌렀다💛")
// rootView.endEditing(true)
//
// }
//
// func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
// rootView.listWeatherLabel.isHidden = true
//
// //이동 위치 구체적 설정 + 키보드 비동기처리 해야 함
// rootView.listScrollView.setContentOffset(CGPoint(x: 0 ,y: 80), animated: true)
// rootView.listWeatherSearchBar.showsCancelButton = true
// }
//
// func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
// rootView.listWeatherLabel.isHidden = false
// rootView.listScrollView.setContentOffset(CGPoint(x: 0 ,y: 0), animated: true)
// rootView.listWeatherSearchBar.showsCancelButton = false
// }
//
// func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
// if searchText.isEmpty {
//
// }
// else {
// var filter = listData.filter {$0.place.lowercased().contains(searchText.lowercased())}
// print("\(filter)💗")
//
// rootView.listStackView.arrangedSubviews.forEach {
// rootView.listStackView.removeArrangedSubview($0)
// rootView.listStackView.removeFromSuperview()
// }
//
// var i = 0
// for reloadList in filter {
// let reloadButton = ListBaseButton()
// reloadButton.do {
// $0.placeLabel.text = listData[i].place
// $0.timeLabel.text = listData[i].time
// $0.weatherLabel.text = listData[i].weather
// $0.currentTemLabel.text = listData[i].currentTem + "°"
// $0.highTemLabel.text = "최고:" + listData[i].highTem + "°"
// $0.lowTemLabel.text = "최저:" + listData[i].lowTem + "°"
// $0.tag = i
//
// rootView.listStackView.addArrangedSubview(reloadButton)
// }
// i = i+1
// }
// rootView.listScrollView.reloadInputViews()
// }
// }
//}
extension ListViewController: UISearchBarDelegate {
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
print("cancel")
rootView.listWeatherSearchBar.searchTextField.text = ""
rootView.endEditing(true)
}

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("눌렀다💛")
rootView.endEditing(true)

}

func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
rootView.listWeatherLabel.isHidden = true

//이동 위치 구체적 설정 + 키보드 비동기처리 해야 함
rootView.listScrollView.setContentOffset(CGPoint(x: 0 ,y: 80), animated: true)
rootView.listWeatherSearchBar.showsCancelButton = true
}

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
rootView.listWeatherLabel.isHidden = false
rootView.listScrollView.setContentOffset(CGPoint(x: 0 ,y: 0), animated: true)
rootView.listWeatherSearchBar.showsCancelButton = false
}

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if searchText.isEmpty {

}
else {
var filter = listData.filter {$0.place.lowercased().contains(searchText.lowercased())}
print("\(filter)💗")

rootView.listStackView.arrangedSubviews.forEach {
rootView.listStackView.removeArrangedSubview($0)
rootView.listStackView.removeFromSuperview()
}

var i = 0
for reloadList in filter {
let reloadButton = ListBaseButton()
reloadButton.do {
$0.placeLabel.text = listData[i].place
$0.timeLabel.text = listData[i].time
$0.weatherLabel.text = listData[i].weather
$0.currentTemLabel.text = listData[i].currentTem + "°"
$0.highTemLabel.text = "최고:" + listData[i].highTem + "°"
$0.lowTemLabel.text = "최저:" + listData[i].lowTem + "°"
$0.tag = i

rootView.listStackView.addArrangedSubview(reloadButton)
}
i = i+1
}
rootView.listScrollView.reloadInputViews()
}
}
}
2 changes: 1 addition & 1 deletion Weather_App/Weather_App/Detail/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ extension DetailViewController : UICollectionViewDelegate {

extension DetailViewController : UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("🥹\(weatherDummy.count)")
return weatherDummy.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DetailCollectionViewCell.identifier, for: indexPath) as? DetailCollectionViewCell else { return UICollectionViewCell() }
cell.weatherData = weatherDummy[indexPath.row]
print("\(indexPath.row)")
return cell
}
}
4 changes: 2 additions & 2 deletions Weather_App/Weather_App/List/ListTableViewHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ListTableViewHeader: UITableViewHeaderFooterView {
}

listWeatherSearchBar.do {
$0.backgroundColor = .clear
$0.backgroundColor = .white
$0.placeholder = "도시 또는 공항 검색"
$0.barStyle = .black
$0.clipsToBounds = true
Expand All @@ -61,7 +61,7 @@ class ListTableViewHeader: UITableViewHeaderFooterView {

private func layout() {
listWeatherLabel.snp.makeConstraints() {
$0.top.equalToSuperview().inset(53)
$0.top.equalToSuperview()
$0.leading.equalToSuperview().inset(20)
}

Expand Down
29 changes: 19 additions & 10 deletions Weather_App/Weather_App/List/ListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ extension ListViewController : UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: ListTableViewHeader.identifier) as? ListTableViewHeader else { return UIView()}
header.listWeatherSearchBar.delegate = self
if isSearching {
header.listWeatherLabel.isHidden = true
} else {
header.listWeatherLabel.isHidden = false
}
return header
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 169.0 - 16.0
return 88.0
}
}

Expand Down Expand Up @@ -116,20 +111,34 @@ extension ListViewController: ListTableViewCellDelegate {

extension ListViewController : UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
isSearching = true
if searchText.isEmpty {
isFiltering = false
filteredWeatherData = []
searchBar.showsCancelButton = false
} else {
isFiltering = true
filteredWeatherData = weatherDummy.filter { $0.name.lowercased().contains(searchText.lowercased()) }
searchBar.showsCancelButton = true
}
rootView.listTableView.reloadData()
}

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
isSearching = false

func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
searchBar.searchTextField.text = ""
searchBar.showsCancelButton = false
isFiltering = false
filteredWeatherData = []
rootView.listTableView.reloadData()
}

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.endEditing(true)
}
// func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
// }
//
// func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
// }
}

extension ListViewController {
Expand Down
2 changes: 1 addition & 1 deletion Weather_App/Weather_App/Network/CityData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

let Cities = ["gongju", "new york", "chuncheon", "tokyo"]
let Cities = ["Seoul", "new york", "chuncheon", "tokyo", "London", "gongju"]

//let Cities = ["gongju", "gwangju", "gumi", "gunsan", "daegu", "daejeon", "mokpo", "busan", "seosan", "seoul", "sokcho", "suwon", "suncheon", "ulsan", "iksan", "jeonju", "jeju", "cheonan", "cheongju", "chuncheon"]

0 comments on commit 1c3e4a6

Please sign in to comment.