git.iko.soy/dashared/GDproject
on master help sign in
now displaying user profile on tap of the post cell's nameLabel. needs minor modifications in viewDidLoad and viewWillApear
commit93460f8c95c9c7c5c12e6bacc3deb76341ebac8a authorDarya Rednikina <rednikina.com@yandex.ru> dateTue 26 Feb 2019, 13:50 (8 years ago) parent4bdbd67
4 files changed+37−13
GDproject/Constants.swift+3 GDproject/Controller/ News and channels/NewsVC.swift+7 GDproject/Controller/ News and channels/PostViewCell.swift+18−11 GDproject/Controller/Profile/ProfileViewController.swift+9−2
GDproject/Constants.swift+3
@@ -41,3 +41,6 @@ let newsController = "NewsController"
4141
4242/// constant for switching to view controller for log in app
4343let logInController = "LogInController"
44+
45+
46+let profileViewController = "ProfileViewController"
GDproject/Controller/ News and channels/NewsVC.swift+7
@@ -38,6 +38,13 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
3838 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
3939
4040 cell.fill(with: dataSourse[indexPath.row].body, false, post: dataSourse[indexPath.row])
41+
42+ cell.onUserDisplay = { [weak self] (id) in
43+ let vc = self?.viewController!.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
44+ vc.idProfile = id
45+ self?.viewController!.navigationController!.pushViewController(vc, animated: true)
46+ }
47+
4148 cell.selectionStyle = .none
4249 return cell
4350 }
GDproject/Controller/ News and channels/PostViewCell.swift+18−11
@@ -13,12 +13,14 @@ import TinyConstraints
1313
1414class PostViewCell: UITableViewCell
1515{
16− let nameLabel: UILabel = {
17− let label = UILabel()
18− label.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
19− label.text = "vbogomazova"
20− label.font = UIFont.boldSystemFont(ofSize: 16)
21− return label
16+ var onUserDisplay: ((Int)->())?
17+
18+ let nameLabel: UIButton = {
19+ let button = UIButton()
20+ button.setTitleColor(.black, for: .normal)
21+ button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
22+ button.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
23+ return button
2224 }()
2325
2426 let fullNameLabel: UILabel = {
@@ -56,19 +58,19 @@ class PostViewCell: UITableViewCell
5658 let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
5759 let markdown = text
5860 markdownParser.enabledElements = .disabledAutomaticLink
59− markdownParser.header.fontIncrease = 6
61+ markdownParser.header.fontIncrease = 16
6062 markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
6163
6264 let textView = UITextView()
6365 textView.isScrollEnabled = false
6466 textView.isEditable = false
65− textView.isUserInteractionEnabled = false
67+ //textView.isUserInteractionEnabled = false
68+ textView.isSelectable = true
6669 textView.attributedText = markdownParser.parse(markdown)
6770 return textView
6871 }
6972
7073 var views: [UIView] = []
71− var data : [UIImage] = []
7274 var post: Model.Posts?
7375
7476 func fill(with info: [Model.Attachments], _ isFullVersoin: Bool, post: Model.Posts)
@@ -77,14 +79,14 @@ class PostViewCell: UITableViewCell
7779 // important
7880 contentView.subviews.forEach({ $0.removeFromSuperview() })
7981
80− data = []
8182 views = []
8283 for attachment in info
8384 {
8485 views.append(createTextView(with: attachment.markdown))
8586 }
8687
87− nameLabel.text = "\(post.user?.firstName ?? "") \(post.user?.secondName ?? "")"
88+ nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.secondName ?? "")", for: .normal)
89+ nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
8890 fullNameLabel.text = "\(post.authorId)"
8991 setUpInStackView(isFullVersoin)
9092 }
@@ -162,4 +164,9 @@ class PostViewCell: UITableViewCell
162164 commentsSharesStackView.edgesToSuperview(excluding: .top, insets: .bottom(10) + .left(16) + .right(16))
163165 stackView.bottomToTop(of: commentsSharesStackView)
164166 }
167+
168+ @objc func displayProfile(){
169+ print("buttonTapped")
170+ onUserDisplay?(post!.authorId)
171+ }
165172}
GDproject/Controller/Profile/ProfileViewController.swift+9−2
@@ -42,6 +42,7 @@ class ProfileViewController: UIViewController
4242 var user: Model.Users? {
4343 didSet {
4444 self.fill(with: user!)
45+ navigationItem.title = "\(user?.id ?? 0)"
4546 }
4647 }
4748
@@ -79,8 +80,14 @@ class ProfileViewController: UIViewController
7980 tableView.reloadData()
8081 }
8182
83+ var idProfile: Int?
84+
8285 override func viewWillAppear(_ animated: Bool) {
83− if let id = DataStorage.standard.getUserId() {
86+ if idProfile == nil {
87+ idProfile = DataStorage.standard.getUserId()
88+ }
89+
90+ if let id = idProfile {
8491 if let user = Model.idUser[id] {
8592 self.user = user
8693 } else {
@@ -99,7 +106,7 @@ class ProfileViewController: UIViewController
99106
100107 func setUpNavigarionBar(){
101108 navigationController?.navigationBar.prefersLargeTitles = true
102− navigationItem.title = "\(DataStorage.standard.getUserId() ?? 0)"
109+ //navigationItem.title = "\(user?.id ?? 0)"
103110 let uibarbutton = UIBarButtonItem(title: "More", style: .plain, target: self, action: #selector(showInformation))
104111 navigationItem.rightBarButtonItems = [uibarbutton]
105112 navigationItem.largeTitleDisplayMode = .always