Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchBar 작동 부자연스러운 문제 #29

Closed
yeahg-dev opened this issue Feb 18, 2023 · 0 comments
Closed

SearchBar 작동 부자연스러운 문제 #29

yeahg-dev opened this issue Feb 18, 2023 · 0 comments
Assignees
Labels
Bug🔥 Something isn't working

Comments

@yeahg-dev
Copy link
Owner

yeahg-dev commented Feb 18, 2023

🚨 문제 설명

환경

  • Xcode 14.0
  • target iOS 15.5

문제

  • 검색 결과 화면에서 searchBar를 탭하고 한 글자를 타이핑해야 최근 검색어로 전환되어 사용상의 불편함 야기
  • 최근 검색어 화면에서 검색 기능 활성화 뷰(header)까지 스크롤 되지 않는 버그

✅ 해결 방법

문제 분석 & 해결 방법

  1. 검색 결과 화면에서 searchBar를 탭하고 한 글자를 타이핑해야 최근 검색어로 전환
    • 기존에는 searchBar의 delegateMethod에서 분기문을 통해 RecenctSearchKeywordTableView를 보여주었다.
    • 분기문을 탈 필요 없이, SearchBar가 탭되었을 때 RecenctSearchKeywordTableView를 보여주면 되므로, searchBarTextDidBeginEditingshowRecentSearchKeywordTableView를 호출하여 해결했다
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
       searchController.showsSearchResultsController = true
       searchAppResultsController.showRecentSearchKeywordTableView()
   }
  1. 최근 검색어 화면에서 검색 기능 활성화 뷰(header)까지 스크롤 되지 않는 버그
    • scrollToTop내부에서 첫번째 cell까지 이동했기 때문에 header는 보여주지 못했다.
    • 따라서 headerView까지 포함된 뷰인 tableViewbounds.origin.y를 searchBar의 높이로 지정해주어 headerView의 존재 유무에 상관 없이 tableView를 모두 보여주도록 수정했다.
    func scrollToTop() {
        guard let searchBarHeight = navigationItem.searchController?.searchBar.bounds.height else {
            return
        }
        tableView.bounds.origin.y = searchBarHeight
    }

👩🏻‍💻결과와 피드백

  • 의도한대로 searchBar의 사용성이 개선되었다.
  • UIKit의 API가 존재하지 않을 때, View의 계층구조와 좌표체계를 활용하는 방법도 있다는 것을 배웠다
@yeahg-dev yeahg-dev added the Bug🔥 Something isn't working label Feb 18, 2023
@yeahg-dev yeahg-dev self-assigned this Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug🔥 Something isn't working
Projects
Status: Done
Development

No branches or pull requests

1 participant