21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
*/
import UIKit
import ObjFW
class MainViewController: UIViewController, UISearchBarDelegate,
UITableViewDelegate, UITableViewDataSource {
public var sites = OFArray<OFString>()
public var siteStorage = SiteStorage()
@IBOutlet var searchBar: UISearchBar?
@IBOutlet var tableView: UITableView?
override func viewDidLoad() {
super.viewDidLoad()
|
|
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
*/
import UIKit
import ObjFW
class MainViewController: UIViewController, UISearchBarDelegate,
UITableViewDelegate, UITableViewDataSource {
public var sites: [String] = []
public var siteStorage = SiteStorage()
@IBOutlet var searchBar: UISearchBar?
@IBOutlet var tableView: UITableView?
override func viewDidLoad() {
super.viewDidLoad()
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
return sites.count
}
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "site") ??
UITableViewCell(style: .default, reuseIdentifier: "site")
cell.textLabel?.text = sites[indexPath.row].nsObject
return cell
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
sites = siteStorage.sites(withFilter: searchBar.text?.ofObject)
tableView?.reloadData()
}
func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "showDetails", sender: self)
}
|
|
|
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
return sites.count
}
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "site") ??
UITableViewCell(style: .default, reuseIdentifier: "site")
cell.textLabel?.text = sites[indexPath.row]
return cell
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
sites = siteStorage.sites(withFilter: searchBar.text)
tableView?.reloadData()
}
func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "showDetails", sender: self)
}
|