我正在尝试添加搜索到我的tableview,我找不到如何过滤搜索结果。我正在从API解析JSON。
class AuthorTableView: UITableViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating, UISearchControllerDelegate {
@IBOutlet weak var searchBar: UISearchBar!
var authorList: [JSON]? = [] //Data from remote API
//search
var searchController: UISearchController?
var searchResultsController: UITableViewController?
var filteredList: [JSON]? = []
override func viewDidLoad() {
super.viewDidLoad()
self.searchBarObj.delegate = self
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
searchController.hidesNavigationBarDuringPresentation = false
definesPresentationContext = true
loadAuthorList()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.hideSearchBar()
}
func hideSearchBar() {
let yOffset = self.navigationController!.navigationBar.bounds.height + UIApplication.sharedApplication().statusBarFrame.height
self.tableView.contentOffset = CGPointMake(0, self.searchController!.searchBar.bounds.height - yOffset)
}
func didDismissSearchController(searchController: UISearchController) {
UIView.animateKeyframesWithDuration(0.5, delay: 0, options: UIViewKeyframeAnimationOptions.BeginFromCurrentState, animations: { () -> Void in
self.hideSearchBar()
}, completion: nil)
}
我应该如何实施搜索过滤器?
func updateSearchResultsForSearchController(searchController: UISearchController) {
...
}