-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResultDisplayVC.swift
62 lines (37 loc) · 1.49 KB
/
ResultDisplayVC.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// ResultDisplayVC.swift
// KatesSearchInTableList
//
// Created by KatesAndroid on 2021/1/28 PM 7:30 - 9:30
// using UISearchResultsUpdating
import UIKit
class ResultDisplayVC: UITableViewController, UISearchResultsUpdating {
let ad = UIApplication.shared.delegate as! AppDelegate
var filter: [String]? // nullable
override func viewDidLoad() {
super.viewDidLoad()
}
//---------tableView-----------
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filter?.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellcell", for: indexPath)
cell.textLabel?.text = filter?[indexPath.row]
return cell
}
//-------UISearchResultsUpdating---------
// match phase
// UISearchResultsUpdating
func updateSearchResults(for searchController: UISearchController) {
if let textRandom = searchController.searchBar.text{
filter = ad.listForAll.filter({ (string) -> Bool in
return (string.range(of: textRandom) != nil)
})
tableView.reloadData()
}
}
}