@@ -8,11 +8,39 @@
88
99import UIKit
1010import TinyConstraints
11+import Cartography
1112
1213// MARK:- Controller with posts and channels availiable.
1314// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
14−class NewsController: UIViewController
15+class NewsController: UIViewController, UISearchControllerDelegate, UITableViewDelegate, UITableViewDataSource
1516{
17+
18+
19+ var array = ["Faculty 1", "Faculty 2","Faculty 3","Faculty 4","Faculty 5","Faculty 6","Faculty 7","Faculty 8","Faculty 9","Faculty 10","Faculty 11","Faculty 12","Faculty 13","Faculty 14","Faculty 15","Faculty 16","Faculty 17","Faculty 18"]
20+
21+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
22+ return array.count
23+ }
24+
25+
26+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
27+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
28+
29+ cell.textLabel?.text = array[indexPath.row]
30+ return cell
31+ }
32+
33+ func presentSearchController(_ searchController: UISearchController) {
34+ print("here")
35+ setUpTableView()
36+ displayTableView() //setup
37+ // this is 0.3
38+ animateTable(some: true)
39+ }
40+
41+ func willDismissSearchController(_ searchController: UISearchController) {
42+ dismissTable()
43+ }
1644
1745 @IBOutlet weak var tableView: UITableView!
1846
@@ -21,24 +49,25 @@ class NewsController: UIViewController
2149 var dataSourse: [Post] = [Post(dataArray: [.text("Le Lorem Ipsum est simplement du faux texte employé dans la composition et la mise en page avant impression. Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen de polices de texte. Il n'a pas fait que survivre cinq siècles, mais s'est aussi adapté à la bureautique informatique, sans que son contenu n'en soit modifié. Il a été popularisé dans les années 1960 grâce à la vente de feuilles Letraset contenant des passages du Lorem Ipsum, et, plus récemment, par son inclusion dans des applications de mise en page de texte, comme Aldus PageMaker. \n On sait depuis longtemps que travailler avec du texte lisible et contenant du sens est source de distractions, et empêche de se concentrer sur la mise en page elle-même. L'avantage du Lorem Ipsum sur un texte générique comme 'Du texte. Du texte. Du texte.' est qu'il possède une distribution de lettres plus ou moins normale, et en tout cas comparable avec celle du français standard. De nombreuses suites logicielles de mise en page ou éditeurs de sites Web ont fait du Lorem Ipsum leur faux texte par défaut, et une recherche pour 'Lorem Ipsum' vous conduira vers de nombreux sites qui n'en sont encore qu'à leur phase de construction. Plusieurs versions sont apparues avec le temps, parfois par accident, souvent intentionnellement (histoire d'y rajouter de petits clins d'oeil, voire des phrases embarassantes).")], from: User(name: "vbogomazova", id: 2, fullName: "Богомазова Вероника Львовна"), date: "14.02.19 в 12:05")]
2250
2351 var news = NewsVC()
24− var channels = ChannelsController()
2552
2653 override func viewDidLoad()
2754 {
2855 super.viewDidLoad()
29− tableView.register(HeaderNewsChannels.self, forCellReuseIdentifier: headerNewsChannelsVC)
3056 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
57+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
58+
59+ //searchController.delegate = self
60+ searchController.obscuresBackgroundDuringPresentation = false
3161
3262 news.dataSourse = dataSourse
3363 news.viewController = self
3464
35− news.type = .NEWS("Posts", "Channels")
3665
3766 tableView.delegate = news
3867 tableView.dataSource = news
3968 tableView.reloadData()
4069
41−
70+ news.type = .NEWS
4271
4372 setUpNavigationItemsforPosts()
4473 searchController.searchBar.placeholder = "Search anything"
@@ -49,8 +78,55 @@ class NewsController: UIViewController
4978 setUpBanner()
5079 }
5180
81+
82+ var facultyTableView = UITableView()
83+
84+ func setUpTableView()
85+ {
86+ facultyTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
87+ facultyTableView.delegate = self
88+ facultyTableView.dataSource = self
89+ let screenSize: CGRect = UIScreen.main.bounds
90+
91+ let screenWidth = screenSize.width
92+ let screenHeight = screenSize.height
93+ facultyTableView.frame = CGRect(x: 0, y: 0, width: Int(screenWidth), height: Int(screenHeight))
94+ }
95+
96+ func displayTableView(){
97+
98+ // the most important line
99+ facultyTableView.translatesAutoresizingMaskIntoConstraints = false
100+ facultyTableView.backgroundColor = UIColor(white: 1, alpha: 1)
101+ view.addSubview(facultyTableView)
102+
103+ facultyTableView.isHidden = true
104+
105+ // now
106+ constrain(facultyTableView, view){
107+ tableView, view in
108+
109+ tableView.top == view.safeAreaLayoutGuide.top
110+ tableView.left == view.left
111+ tableView.right == view.right
112+ tableView.bottom == view.safeAreaLayoutGuide.bottom
113+ }
114+
115+ }
116+
117+ // animation of the table cells
118+ func animateTable(some: Bool){
119+ self.facultyTableView.reloadData()
120+ self.facultyTableView.isHidden = false
121+ }
122+
123+ func dismissTable() {
124+ self.facultyTableView.isHidden = true
125+ }
126+
52127 override func viewWillAppear(_ animated: Bool) {
53128 super.viewWillAppear(animated)
129+ print("hello")
54130 navigationController?.navigationBar.prefersLargeTitles = true
55131 }
56132
@@ -62,13 +138,7 @@ class NewsController: UIViewController
62138 tableView.reloadData()
63139 }
64140
65− func setUpNavigationItemsForChannels(){
66− navigationItem.title = "Channels"
67− navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
68− tableView.delegate = channels
69− tableView.dataSource = channels
70− tableView.reloadData()
71− }
141+ //navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
72142
73143 @objc func writePost(_ barItem: UIBarButtonItem)
74144 {