git.iko.soy/dashared/GDproject
on master help sign in
full post view and slight modifications
commit973f0ed97b24d1d0f5993224780323632a68d2e2 authorDarya Rednikina <rednikina.com@yandex.ru> dateThu 14 Feb 2019, 00:07 (8 years ago) parentf7fc725
7 files changed+96−7
GDproject.xcodeproj/project.pbxproj+4 GDproject/Base.lproj/Main.storyboard+18 GDproject/Constants.swift+2 GDproject/Controller/FullPostController.swift+49 GDproject/Controller/NewsController.swift+8−2 GDproject/Controller/PostViewCell.swift+6−4 GDproject/Simple model/Post.swift+9−1
GDproject.xcodeproj/project.pbxproj+4
@@ -26,6 +26,7 @@
2626 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DC922144635006FCDD7 /* NewPostViewController.swift */; };
2727 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCB22144725006FCDD7 /* PostViewCell.swift */; };
2828 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCD22144756006FCDD7 /* Constants.swift */; };
29+ 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD022148122006FCDD7 /* FullPostController.swift */; };
2930/* End PBXBuildFile section */
3031
3132/* Begin PBXCopyFilesBuildPhase section */
@@ -64,6 +65,7 @@
6465 12E36DC922144635006FCDD7 /* NewPostViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPostViewController.swift; sourceTree = "<group>"; };
6566 12E36DCB22144725006FCDD7 /* PostViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewCell.swift; sourceTree = "<group>"; };
6667 12E36DCD22144756006FCDD7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
68+ 12E36DD022148122006FCDD7 /* FullPostController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullPostController.swift; sourceTree = "<group>"; };
6769/* End PBXFileReference section */
6870
6971/* Begin PBXFrameworksBuildPhase section */
@@ -135,6 +137,7 @@
135137 12E36DCF22145923006FCDD7 /* Controller */ = {
136138 isa = PBXGroup;
137139 children = (
140+ 12E36DD022148122006FCDD7 /* FullPostController.swift */,
138141 12E36DC522144266006FCDD7 /* HeaderNewsChannels.swift */,
139142 12E36DC722144374006FCDD7 /* ChannelsController.swift */,
140143 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
@@ -223,6 +226,7 @@
223226 12E36D9E221424EA006FCDD7 /* NewsController.swift in Sources */,
224227 12E36DC622144266006FCDD7 /* HeaderNewsChannels.swift in Sources */,
225228 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */,
229+ 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */,
226230 12E36D9C221424EA006FCDD7 /* AppDelegate.swift in Sources */,
227231 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */,
228232 );
GDproject/Base.lproj/Main.storyboard+18
@@ -72,6 +72,24 @@
7272 </objects>
7373 <point key="canvasLocation" x="1773" y="132"/>
7474 </scene>
75+ <!--Full Post Controller-->
76+ <scene sceneID="nNH-1Q-jks">
77+ <objects>
78+ <tableViewController storyboardIdentifier="FullPostController" id="tcM-Fs-WJr" customClass="FullPostController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
79+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="dmU-W2-lq6">
80+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
81+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
82+ <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
83+ <connections>
84+ <outlet property="dataSource" destination="tcM-Fs-WJr" id="Xvi-Mj-Id2"/>
85+ <outlet property="delegate" destination="tcM-Fs-WJr" id="190-Q0-2bn"/>
86+ </connections>
87+ </tableView>
88+ </tableViewController>
89+ <placeholder placeholderIdentifier="IBFirstResponder" id="CP8-RO-wn0" userLabel="First Responder" sceneMemberID="firstResponder"/>
90+ </objects>
91+ <point key="canvasLocation" x="2506" y="130"/>
92+ </scene>
7593 <!--Navigation Controller-->
7694 <scene sceneID="RSd-UJ-34B">
7795 <objects>
GDproject/Constants.swift+2
@@ -10,3 +10,5 @@
1010let postCellId = "PostCell"
1111// constant for segmented controll in NewsController.swift and ChannelsController.swift
1212let headerNewsChannelsVC = "HeaderSegmentedControll"
13+// for transitioning to full post view
14+let fullPostControllerId = "FullPostController"
GDproject/Controller/FullPostController.swiftnew file+49
@@ -0,0 +1,49 @@
1+//
2+// FullPostViewController.swift
3+// GDproject
4+//
5+// Created by cstore on 13/02/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class FullPostController: UITableViewController {
12+
13+ var post: Post?
14+
15+ override func viewDidLoad() {
16+ super.viewDidLoad()
17+
18+ tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
19+ }
20+
21+ // MARK: - Table view data source
22+
23+ override func numberOfSections(in tableView: UITableView) -> Int {
24+ // #warning Incomplete implementation, return the number of sections
25+ return 2
26+ }
27+
28+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
29+ {
30+ switch section {
31+ case 0:
32+ return 1
33+ case 1:
34+ return post?.comments.count ?? 0
35+ default:
36+ return 0
37+ }
38+ }
39+
40+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
41+ {
42+ // TODO: make different cells for sections with switch
43+
44+ let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
45+
46+ cell.fill(with: post!.dataArray, true)
47+ return cell
48+ }
49+}
GDproject/Controller/NewsController.swift+8−2
@@ -69,7 +69,13 @@ class NewsController: UIViewController
6969
7070// MARK:- tableView delegate
7171extension NewsController: UITableViewDelegate{
72−
72+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
73+ {
74+ let vc = storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
75+
76+ vc.post = dataSourse[indexPath.row]
77+ navigationController!.pushViewController(vc, animated: true)
78+ }
7379}
7480
7581// MARK:- tableView dataSourse
@@ -82,7 +88,7 @@ extension NewsController: UITableViewDataSource
8288 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
8389 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
8490
85− cell.fill(with: dataSourse[indexPath.row].dataArray)
91+ cell.fill(with: dataSourse[indexPath.row].dataArray, false)
8692 return cell
8793 }
8894
GDproject/Controller/PostViewCell.swift+6−4
@@ -58,7 +58,7 @@ class PostViewCell: UITableViewCell
5858 var views: [UIView] = []
5959 var data : [UIImage] = []
6060
61− func fill(with info: [Media])
61+ func fill(with info: [Media], _ isFullVersoin: Bool)
6262 {
6363 // important
6464 contentView.subviews.forEach({ $0.removeFromSuperview() })
@@ -77,10 +77,10 @@ class PostViewCell: UITableViewCell
7777 break
7878 }
7979 }
80− setUpInStackView()
80+ setUpInStackView(isFullVersoin)
8181 }
8282
83− func setUpInStackView(){
83+ func setUpInStackView(_ full : Bool){
8484 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
8585 nameStackView.axis = .vertical
8686 contentView.addSubview(nameStackView)
@@ -90,7 +90,9 @@ class PostViewCell: UITableViewCell
9090 let stackView = UIStackView(arrangedSubviews: views)
9191 stackView.axis = .vertical
9292 contentView.addSubview(stackView)
93− stackView.height(300, relation: .equalOrLess, isActive: true)
93+ if !full {
94+ stackView.height(300, relation: .equalOrLess, isActive: true)
95+ }
9496 stackView.topToBottom(of: nameStackView)
9597 stackView.edgesToSuperview(excluding: .top, insets: .bottom(8) + .left(16) + .right(16))
9698 }
GDproject/Simple model/Post.swift+9−1
@@ -13,12 +13,14 @@ struct Post {
1313 var dataArray: [Media]
1414 var fromUser: User
1515 var atDate: String
16+ var comments: [Comment]
1617
17− init(dataArray: [Media], from: User, date: String)
18+ init(dataArray: [Media], from: User, date: String, comments: [Comment] = [])
1819 {
1920 self.dataArray = dataArray
2021 fromUser = from
2122 atDate = date
23+ self.comments = comments
2224 }
2325}
2426
@@ -28,3 +30,9 @@ enum Media{
2830 case image([UIImage])
2931 case quote
3032}
33+
34+struct Comment {
35+ var from: User
36+ var atTime: String
37+ var withData: String
38+}