@@ -17,12 +17,17 @@ protocol NewPostDelegate {
18// MARK:- Controller with posts and channels availiable.
18// MARK:- Controller with posts and channels availiable.
19// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
19// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
20−class NewsController: UIViewController, UISearchControllerDelegate, UITableViewDelegate, UITableViewDataSource, DataDelegate, NewPostDelegate
20+class NewsController: UITableViewController, UISearchControllerDelegate, DataDelegate, NewPostDelegate
22+ var currentChannel: Channel?{
24+ news.dataSourse = currentChannel?.posts ?? []
25+ navigationItem.title = currentChannel?.title ?? ""
23 func passData(for row: Int, channel: Channel) {
29 func passData(for row: Int, channel: Channel) {
24− news.dataSourse = channel.posts
30+ currentChannel = channel
25− navigationItem.title = channel.title
28 func addPost(post: Post) {
33 func addPost(post: Post) {
@@ -31,12 +36,12 @@ class NewsController: UIViewController, UISearchControllerDelegate, UITableViewD
32 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"]
37 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"]
34− func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
39+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
35 return array.count
40 return array.count
39− func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
44+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
40 let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
45 let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
42 cell.textLabel?.text = array[indexPath.row]
47 cell.textLabel?.text = array[indexPath.row]
@@ -55,24 +60,31 @@ class NewsController: UIViewController, UISearchControllerDelegate, UITableViewD
55 dismissTable()
60 dismissTable()
58− @IBOutlet weak var tableView: UITableView!
63+ //@IBOutlet weak var tableView: UITableView!
60 var searchController = UISearchController(searchResultsController: nil)
65 var searchController = UISearchController(searchResultsController: nil)
62− 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")]
64 var news = NewsVC()
68 var news = NewsVC()
66 override func viewDidLoad()
70 override func viewDidLoad()
68 super.viewDidLoad()
72 super.viewDidLoad()
74+ //view.backgroundColor = .white
75+ currentChannel = ChannelListController.dataSource[0]
77+ view.addSubview(label)
78+ //label.horizontalToSuperview(insets: .left(30) + .right(30))
79+ //label.verticalToSuperview()
69 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
81 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
70 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
82 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
72 searchController.delegate = self
84 searchController.delegate = self
73 searchController.obscuresBackgroundDuringPresentation = false
85 searchController.obscuresBackgroundDuringPresentation = false
75− news.dataSourse = dataSourse
87+ news.dataSourse = currentChannel!.posts
76 news.viewController = self
88 news.viewController = self
@@ -80,7 +92,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UITableViewD
80 tableView.dataSource = news
92 tableView.dataSource = news
81 tableView.reloadData()
93 tableView.reloadData()
83− news.type = .NEWS
95+ news.type = .NONE
85 setUpNavigationItemsforPosts()
97 setUpNavigationItemsforPosts()
86 searchController.searchBar.placeholder = "Search anything"
98 searchController.searchBar.placeholder = "Search anything"
@@ -137,22 +149,44 @@ class NewsController: UIViewController, UISearchControllerDelegate, UITableViewD
137 self.facultyTableView.isHidden = true
149 self.facultyTableView.isHidden = true
152+ let label : UILabel = {
153+ let label = UILabel()
154+ label.text = "No posts to display yet!"
155+ label.font = UIFont.systemFont(ofSize: 18)
156+ label.textColor = .black
157+ label.isHidden = true
158+ label.numberOfLines = 0
140 override func viewWillAppear(_ animated: Bool) {
162 override func viewWillAppear(_ animated: Bool) {
141 super.viewWillAppear(animated)
163 super.viewWillAppear(animated)
142 print("hello")
164 print("hello")
143 navigationController?.navigationBar.prefersLargeTitles = true
165 navigationController?.navigationBar.prefersLargeTitles = true
166+ if currentChannel!.posts.isEmpty {
167+ //tableView.isHidden = true
168+ label.isHidden = false
170+ label.isHidden = true
171+ tableView.isHidden = false
144− tableView.reloadData()
172+ tableView.reloadData()
147 func setUpNavigationItemsforPosts(){
176 func setUpNavigationItemsforPosts(){
148− navigationItem.title = "Posts"
177+ navigationItem.rightBarButtonItems = [
149− navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:)))]
178+ UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),
179+ UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))]
150 tableView.delegate = news
180 tableView.delegate = news
151 tableView.dataSource = news
181 tableView.dataSource = news
152 tableView.reloadData()
182 tableView.reloadData()
155−
185+ @objc func showChannels(_ barItem: UIBarButtonItem){
186+ let vc = storyboard!.instantiateViewController(withIdentifier: channelListControllerId) as! ChannelListController
187+ vc.myProtocol = self
188+ self.navigationController!.pushViewController(vc, animated: true)
157 @objc func writePost(_ barItem: UIBarButtonItem)
191 @objc func writePost(_ barItem: UIBarButtonItem)
@@ -231,7 +265,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UITableViewD
232 var isBannerVisible: Bool = false
266 var isBannerVisible: Bool = false
234− func scrollViewDidScroll(_ scrollView: UIScrollView) {
268+ override func scrollViewDidScroll(_ scrollView: UIScrollView) {
235 print(scrollView.contentOffset.y)
269 print(scrollView.contentOffset.y)
236 if scrollView.contentOffset.y >= 50 && !isBannerVisible{
270 if scrollView.contentOffset.y >= 50 && !isBannerVisible{
237 isBannerVisible = true
271 isBannerVisible = true