@@ -19,8 +19,12 @@ protocol NewPostDelegate {
1919
2020// MARK:- Controller with posts and channels availiable.
2121// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
22−class NewsController: UITableViewController, UISearchControllerDelegate, NewPostDelegate, UpdateableWithChannel
22+class NewsController: UITableViewController, UISearchControllerDelegate, NewPostDelegate, UpdateableWithChannel, DataDelegate
2323{
24+ func passData(for row: Int, channel: Channel) {
25+ self.channel = channel
26+ }
27+
2428 var channel: Channel?{
2529 didSet{
2630 news.dataSourse = channel?.posts ?? []
@@ -35,120 +39,34 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
3539 news.dataSourse.insert(post, at: 0)
3640 }
3741
38− 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"]
39−
40− override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
41− return array.count
42− }
43−
44−
45− override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
46− let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
47−
48− cell.textLabel?.text = array[indexPath.row]
49− return cell
50− }
51−
52− func presentSearchController(_ searchController: UISearchController) {
53− print("here")
54− setUpTableView()
55− displayTableView() //setup
56− // this is 0.3
57− animateTable(some: true)
58− }
59−
60− func willDismissSearchController(_ searchController: UISearchController) {
61− dismissTable()
62− }
63−
64− //@IBOutlet weak var tableView: UITableView!
65−
6642 var searchController = UISearchController(searchResultsController: nil)
6743
68−
6944 var news = NewsVC()
7045
7146 override func viewDidLoad()
7247 {
7348 super.viewDidLoad()
74−
75− //view.backgroundColor = .white
7649 channel = ChannelListController.dataSource[0]
7750
78− view.addSubview(label)
79− //label.horizontalToSuperview(insets: .left(30) + .right(30))
80− //label.verticalToSuperview()
81−
8251 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
8352 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
8453
8554 searchController.delegate = self
8655 searchController.obscuresBackgroundDuringPresentation = false
56+ navigationItem.searchController = searchController
57+ definesPresentationContext = true
58+ searchController.searchBar.placeholder = "Search anything"
8759
8860 news.dataSourse = channel!.posts
8961 news.viewController = self
9062
91−
92− tableView.delegate = news
93− tableView.dataSource = news
94− tableView.reloadData()
95−
9663 news.type = .NONE
9764
9865 setUpNavigationItemsforPosts()
99− searchController.searchBar.placeholder = "Search anything"
100−
101− navigationItem.searchController = searchController
102− definesPresentationContext = true
103−
104− setUpBanner()
105− }
106−
107−
108− var facultyTableView = UITableView()
109−
110− func setUpTableView()
111− {
112− facultyTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
113− facultyTableView.delegate = self
114− facultyTableView.dataSource = self
115− let screenSize: CGRect = UIScreen.main.bounds
116−
117− let screenWidth = screenSize.width
118− let screenHeight = screenSize.height
119− facultyTableView.frame = CGRect(x: 0, y: 0, width: Int(screenWidth), height: Int(screenHeight))
120− }
121−
122− func displayTableView(){
123−
124− // the most important line
125− facultyTableView.translatesAutoresizingMaskIntoConstraints = false
126− facultyTableView.backgroundColor = UIColor(white: 1, alpha: 1)
127− view.addSubview(facultyTableView)
128−
129− facultyTableView.isHidden = true
130−
131− // now
132− constrain(facultyTableView, view){
133− tableView, view in
134−
135− tableView.top == view.safeAreaLayoutGuide.top
136− tableView.left == view.left
137− tableView.right == view.right
138− tableView.bottom == view.safeAreaLayoutGuide.bottom
139− }
140−
66+
67+ //setUpBanner()
14168 }
14269
143− // animation of the table cells
144− func animateTable(some: Bool){
145− self.facultyTableView.reloadData()
146− self.facultyTableView.isHidden = false
147− }
148−
149− func dismissTable() {
150− self.facultyTableView.isHidden = true
151− }
15270
15371 let label : UILabel = {
15472 let label = UILabel()
@@ -162,22 +80,14 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
16280
16381 override func viewWillAppear(_ animated: Bool) {
16482 super.viewWillAppear(animated)
165− print("hello")
166− navigationController?.navigationBar.prefersLargeTitles = true
167− if channel!.posts.isEmpty {
168− //tableView.isHidden = true
169− label.isHidden = false
170− } else {
171− label.isHidden = true
172− tableView.isHidden = false
173− tableView.reloadData()
174− }
83+ searchController.isActive = false
84+ // TODO:- display something if no posts are availiable
85+ tableView.reloadData()
17586 }
17687
17788 func setUpNavigationItemsforPosts(){
178− navigationItem.rightBarButtonItems = [
179− UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),
180− UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))]
89+ navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))
90+ ]
18191 tableView.delegate = news
18292 tableView.dataSource = news
18393 tableView.reloadData()
@@ -185,7 +95,10 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
18595
18696 // MARK:- attempt with coordinator
18797 @objc func showChannels(_ barItem: UIBarButtonItem){
188− onSelectChannel?()
98+ let vc = UIStoryboard.makeChannelsListController()
99+ vc.myProtocol = self
100+ vc.displayingChannel = channel
101+ self.navigationController?.pushViewController(vc, animated: true)
189102 }
190103
191104 @objc func writePost(_ barItem: UIBarButtonItem)
@@ -206,8 +119,6 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
206119 navigationController?.pushViewController(vc, animated: false)
207120 }
208121
209−
210−
211122 // for animating the banner
212123 var topConstraint: NSLayoutConstraint?
213124
@@ -227,6 +138,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
227138 return label
228139 }()
229140
141+ // MARK:- banner
230142 private func setUpBanner()
231143 {
232144 view.addSubview(bannerView)