UISearchBar in a UITableView

后端 未结 2 1854
鱼传尺愫
鱼传尺愫 2021-02-06 17:00

I\'m trying to mimic the behaviour of a table view similar to the iPod app for Artists - it\'s a sectioned table view with a section index on the right, with a search bar at the

2条回答
  •  无人共我
    2021-02-06 17:57

    Answered my own question, but might be helpful to other beginners:

    • Put the search bar in the table view header when view loads, scroll contentOffset down the height of this search bar (typically 44 pixels), but easy to check dynamically
    • Add a search icon in the section index with "{search}"
    • Make the sectionIndexSection for the search -1
    • When handling section index touches use the 'special' index value for search "-1" (to scroll the contentOffset back to (0, 0)

    Update: use the string constant UITableViewIndexSearch string in place of the undocumented string "{search}" - i.e. return it as one of the array items when implementing:

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
    

    in UITableViewDataSource.

提交回复
热议问题