Skip to content

Commit

Permalink
Merge pull request #43 from naneun/chez-search#41
Browse files Browse the repository at this point in the history
[iOS] 검색 창에 단어를 입력한 상태에서 지우기 버튼을 누르면 단어를 초기화 할 수 있음
  • Loading branch information
BumgeunSong committed Jun 6, 2022
2 parents d6c25e8 + 87502b6 commit 7a67f33
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DetailSearchDelegate: NSObject, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

guard let datasource = self.collectionView?.dataSource as? DetailSearchLocationDataSource else { return }
let mapItem = datasource.searchResultData[0]
guard let mapItem = datasource.searchResultData.first else { return }
guard let place = PlaceFactory.makePlace(with: mapItem) else { return }
searchDateVC.queryParameter?.place = place
self.navigationController?.pushViewController(searchDateVC, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class RecommendationDataSource: NSObject, UICollectionViewDataSource {
let location = Location.makeRandomInKR()
let recommendSuccessStubRequest = DefaultRecommendator(httpService: ResponseSuccessStub())


recommendSuccessStubRequest.recommend(for: location) { [weak self] place in
guard let self = self else { return }
guard let place = place else { return }
guard let self = self, let place = place else { return }
self.recommendationData = place
didLoadData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class SearchLocationViewController: UIViewController {
private var detailSearchDataSource: DetailSearchLocationDataSource?
private var detailSearchDelegate: DetailSearchDelegate?

private lazy var clearButton: UIBarButtonItem = {
let button = UIBarButtonItem(title: "지우기", style: .plain, target: self, action: #selector(buttonPressed(_:)))
return button
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
Expand Down Expand Up @@ -64,9 +69,13 @@ class SearchLocationViewController: UIViewController {
private func setSearchBar() {
self.navigationItem.title = SearchLocationViewController.defaultNavTitle
self.navigationItem.searchController = UISearchController(searchResultsController: nil)
self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationController?.hidesBarsOnSwipe = false
self.navigationItem.searchController?.searchBar.delegate = self
self.navigationItem.setRightBarButton(clearButton, animated: true)

self.navigationController?.hidesBarsOnSwipe = false
self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationItem.searchController?.searchBar.showsCancelButton = false
self.navigationItem.searchController?.hidesNavigationBarDuringPresentation = false

navigationItem.searchController?.isActive = true
navigationItem.searchController?.searchBar.becomeFirstResponder()
Expand All @@ -91,6 +100,16 @@ class SearchLocationViewController: UIViewController {
collectionView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: 16).isActive = true
collectionView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
}

@objc
private func buttonPressed(_ sender: Any){
collectionView.delegate = recommendationDelegate
collectionView.dataSource = recommendationDataSource
self.navigationItem.searchController?.searchBar.text = nil
DispatchQueue.main.async {
self.collectionView.reloadData()
}
}
}


Expand Down

0 comments on commit 7a67f33

Please sign in to comment.