【发布时间】:2016-01-20 11:09:50
【问题描述】:
我在 tableview 中有一个 searchBar,在 .csv 文件 (coredata) 中搜索结果。
列表很大,因此用户必须在第一次搜索后向上滚动多次才能到达搜索栏,或者在索引栏中选择“A”字母。
当用户想要回到列表的开头时,有没有办法在 NavigationBar 中添加一个按钮来显示 searchBar?提前致谢。
searchController = UISearchController(searchResultsController: nil)
tableView.tableHeaderView = searchController.searchBar
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionTitles[section]
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
//assume a single section after a search
return (searchController.active) ? 1 : sectionTitles.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if searchController.active {
return searchResults.count
} else {
// Return the number of rows in the section.
let wordKey = sectionTitles[section]
if let items = cockpitDict[wordKey] {
return items.count
}
return 0
}
}
【问题讨论】:
标签: core-data swift2 xcode7 uisearchbar