@@ -19,8 +19,12 @@ protocol NewPostDelegate {
20// MARK:- Controller with posts and channels availiable.
20// MARK:- Controller with posts and channels availiable.
21// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
21// 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
24+ func passData(for row: Int, channel: Channel) {
25+ self.channel = channel
24 var channel: Channel?{
28 var channel: Channel?{
26 news.dataSourse = channel?.posts ?? []
30 news.dataSourse = channel?.posts ?? []
@@ -35,120 +39,34 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
35 news.dataSourse.insert(post, at: 0)
39 news.dataSourse.insert(post, at: 0)
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"]
40− override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
45− override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
46− let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
48− cell.textLabel?.text = array[indexPath.row]
52− func presentSearchController(_ searchController: UISearchController) {
55− displayTableView() //setup
57− animateTable(some: true)
60− func willDismissSearchController(_ searchController: UISearchController) {
64− //@IBOutlet weak var tableView: UITableView!
66 var searchController = UISearchController(searchResultsController: nil)
42 var searchController = UISearchController(searchResultsController: nil)
69 var news = NewsVC()
44 var news = NewsVC()
71 override func viewDidLoad()
46 override func viewDidLoad()
73 super.viewDidLoad()
48 super.viewDidLoad()
75− //view.backgroundColor = .white
76 channel = ChannelListController.dataSource[0]
49 channel = ChannelListController.dataSource[0]
78− view.addSubview(label)
79− //label.horizontalToSuperview(insets: .left(30) + .right(30))
80− //label.verticalToSuperview()
82 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
51 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
83 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
52 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
85 searchController.delegate = self
54 searchController.delegate = self
86 searchController.obscuresBackgroundDuringPresentation = false
55 searchController.obscuresBackgroundDuringPresentation = false
56+ navigationItem.searchController = searchController
57+ definesPresentationContext = true
58+ searchController.searchBar.placeholder = "Search anything"
88 news.dataSourse = channel!.posts
60 news.dataSourse = channel!.posts
89 news.viewController = self
61 news.viewController = self
92− tableView.delegate = news
93− tableView.dataSource = news
94− tableView.reloadData()
96 news.type = .NONE
63 news.type = .NONE
98 setUpNavigationItemsforPosts()
65 setUpNavigationItemsforPosts()
99− searchController.searchBar.placeholder = "Search anything"
66+
101− navigationItem.searchController = searchController
102− definesPresentationContext = true
104− setUpBanner()
67+ //setUpBanner()
108− var facultyTableView = UITableView()
110− func setUpTableView()
112− facultyTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
113− facultyTableView.delegate = self
114− facultyTableView.dataSource = self
115− let screenSize: CGRect = UIScreen.main.bounds
117− let screenWidth = screenSize.width
118− let screenHeight = screenSize.height
119− facultyTableView.frame = CGRect(x: 0, y: 0, width: Int(screenWidth), height: Int(screenHeight))
122− func displayTableView(){
124− // the most important line
125− facultyTableView.translatesAutoresizingMaskIntoConstraints = false
126− facultyTableView.backgroundColor = UIColor(white: 1, alpha: 1)
127− view.addSubview(facultyTableView)
129− facultyTableView.isHidden = true
132− constrain(facultyTableView, view){
135− tableView.top == view.safeAreaLayoutGuide.top
136− tableView.left == view.left
137− tableView.right == view.right
138− tableView.bottom == view.safeAreaLayoutGuide.bottom
143− // animation of the table cells
144− func animateTable(some: Bool){
145− self.facultyTableView.reloadData()
146− self.facultyTableView.isHidden = false
149− func dismissTable() {
150− self.facultyTableView.isHidden = true
153 let label : UILabel = {
71 let label : UILabel = {
154 let label = UILabel()
72 let label = UILabel()
@@ -162,22 +80,14 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
163 override func viewWillAppear(_ animated: Bool) {
81 override func viewWillAppear(_ animated: Bool) {
164 super.viewWillAppear(animated)
82 super.viewWillAppear(animated)
165− print("hello")
83+ searchController.isActive = false
166− navigationController?.navigationBar.prefersLargeTitles = true
84+ // TODO:- display something if no posts are availiable
167− if channel!.posts.isEmpty {
168− //tableView.isHidden = true
169− label.isHidden = false
171− label.isHidden = true
172− tableView.isHidden = false
173− tableView.reloadData()
85+ tableView.reloadData()
177 func setUpNavigationItemsforPosts(){
88 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(_:)))
181 tableView.delegate = news
91 tableView.delegate = news
182 tableView.dataSource = news
92 tableView.dataSource = news
183 tableView.reloadData()
93 tableView.reloadData()
@@ -185,7 +95,10 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
186 // MARK:- attempt with coordinator
96 // MARK:- attempt with coordinator
187 @objc func showChannels(_ barItem: UIBarButtonItem){
97 @objc func showChannels(_ barItem: UIBarButtonItem){
188− onSelectChannel?()
98+ let vc = UIStoryboard.makeChannelsListController()
100+ vc.displayingChannel = channel
101+ self.navigationController?.pushViewController(vc, animated: true)
191 @objc func writePost(_ barItem: UIBarButtonItem)
104 @objc func writePost(_ barItem: UIBarButtonItem)
@@ -206,8 +119,6 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
206 navigationController?.pushViewController(vc, animated: false)
119 navigationController?.pushViewController(vc, animated: false)
211 // for animating the banner
122 // for animating the banner
212 var topConstraint: NSLayoutConstraint?
123 var topConstraint: NSLayoutConstraint?
@@ -227,6 +138,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
227 return label
138 return label
230 private func setUpBanner()
142 private func setUpBanner()
232 view.addSubview(bannerView)
144 view.addSubview(bannerView)