This commit is contained in:
Chris Li 2016-12-28 17:05:55 -05:00
parent 0399f1b858
commit 29dfe133c9

View File

@ -13,13 +13,16 @@ import DZNEmptyDataSet
class SearchResultController: SearchBaseTableController, UITableViewDataSource, UITableViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { class SearchResultController: SearchBaseTableController, UITableViewDataSource, UITableViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
private var searchResults = [SearchResult]() private var searchResults = [SearchResult]()
private var searchText = ""
/** /**
Controls if empty table background should be displayed Controls if empty table background should be displayed
- When search text is empty, shouldShowNoResults = false - When search text is empty, shouldShowNoResults = false
- When search text is **not** empty, shouldShowNoResults = true - When search text is **not** empty, shouldShowNoResults = true
*/ */
private var shouldShowNoResults = false private var shouldShowNoResults: Bool {
return searchText != ""
}
override func viewDidLoad() { override func viewDidLoad() {
@ -31,7 +34,7 @@ class SearchResultController: SearchBaseTableController, UITableViewDataSource,
tableView.emptyDataSetDelegate = self tableView.emptyDataSetDelegate = self
} }
func selectFirstResultIfPossible() { func selectFirstResult() {
guard searchResults.count > 0 else {return} guard searchResults.count > 0 else {return}
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: .top) tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: .top)
tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0)) tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0))
@ -43,7 +46,7 @@ class SearchResultController: SearchBaseTableController, UITableViewDataSource,
- Parameter results: An array of search result to be displayed - Parameter results: An array of search result to be displayed
*/ */
func reload(searchText: String, results: [SearchResult]) { func reload(searchText: String, results: [SearchResult]) {
shouldShowNoResults = searchText != "" self.searchText = searchText
searchResults = results searchResults = results
tableView.tableFooterView = searchResults.count > 0 ? nil : UIView() tableView.tableFooterView = searchResults.count > 0 ? nil : UIView()
@ -97,6 +100,7 @@ class SearchResultController: SearchBaseTableController, UITableViewDataSource,
let result = searchResults[indexPath.row] let result = searchResults[indexPath.row]
let operation = ArticleLoadOperation(bookID: result.bookID, articleTitle: result.title) let operation = ArticleLoadOperation(bookID: result.bookID, articleTitle: result.title)
GlobalQueue.shared.add(articleLoadOperation: operation) GlobalQueue.shared.add(articleLoadOperation: operation)
Preference.RecentSearch.add(term: searchText)
} }
// MARK: - DZNEmptyDataSet // MARK: - DZNEmptyDataSet