Guest User

Untitled

a guest
Jul 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. articlesArray = [articleTemplateStruct(articleName: "", clauses: [""], payments: [paymentStruct(amount: "", desc: "")]), articleTemplateStruct(articleName: "", clauses: ["", ""], payments: [paymentStruct(amount: "", desc: ""), paymentStruct(amount: "", desc: "")]) ]
  2.  
  3. func numberOfSections(in tableView: UITableView) -> Int {
  4. if(tableView == articleTableView){
  5. return articlesArray.count
  6. }else{
  7. return 1
  8. }
  9. }
  10.  
  11. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  12.  
  13. if(tableView == articleTableView){
  14. return 1
  15. }else if(tableView.tag == 10){
  16. return articlesArray[section].clauses.count
  17. }else{
  18. return 1
  19. }
  20. }
  21.  
  22. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  23. if(tableView == articleTableView){
  24. let cell = tableView.dequeueReusableCell(withIdentifier: "ContractTemplate", for: indexPath) as! ContractTemplateTableViewCell
  25.  
  26. self.functions.enterValue(textfield: cell.articleTitle, phText: langc.article)
  27.  
  28. cell.separatorInset = .zero
  29.  
  30.  
  31. cell.clauseTableView.register(UINib(nibName: "ContractTemplateSubjectsTableViewCell", bundle: nil), forCellReuseIdentifier: "ContractTemplateSubjects")
  32. cell.paymentTableView.register(UINib(nibName: "ContractTemplatePaymentTableViewCell", bundle: nil), forCellReuseIdentifier: "ContractTemplatePayment")
  33.  
  34.  
  35. cell.clauseTableView.delegate = self
  36. cell.clauseTableView.dataSource = self
  37. cell.clauseTableView.reloadData()
  38. cell.clauseTableView.tableFooterView = UIView()
  39.  
  40.  
  41. cell.clauseTableView.sizeToFit()
  42.  
  43. cell.clauseTableConst.constant = cell.clauseTableView.contentSize.height
  44.  
  45. let artTableHeight = self.articleTableView.contentSize.height
  46.  
  47. tableViewClause = cell.clauseTableView
  48. clauseTableFlag = true
  49.  
  50. cell.paymentTableView.delegate = self
  51. cell.paymentTableView.dataSource = self
  52. cell.paymentTableView.reloadData()
  53. cell.paymentTableView.tableFooterView = UIView()
  54.  
  55.  
  56. cell.paymentTableConst.constant = cell.paymentTableView.contentSize.height
  57.  
  58.  
  59. articleTableConst.constant = artTableHeight + cell.clauseTableView.contentSize.height + cell.paymentTableView.contentSize.height
  60.  
  61.  
  62. containerHeightConst.constant = articleTableView.contentSize.height + 281
  63.  
  64. cell.selectionStyle = .none
  65.  
  66. cell.add.tag = indexPath.section
  67.  
  68. cell.add.addTarget(self, action: #selector(addArticle), for: .touchUpInside)
  69.  
  70. return cell
  71.  
  72. }else if(tableView.tag == 10){
  73.  
  74.  
  75. let cell = tableView.dequeueReusableCell(withIdentifier: "ContractTemplateSubjects", for: indexPath) as! ContractTemplateSubjectsTableViewCell
  76.  
  77. self.functions.textArea(textArea: cell.subjectDesc, text: self.langc.descriptionTxt)
  78.  
  79. cell.tag = indexPath.section*1000 + indexPath.row
  80. cell.add.addTarget(self, action: #selector(addClause), for: .touchUpInside)
  81.  
  82. cell.separatorInset = .zero
  83.  
  84. return cell
  85. }
  86. else{
  87. let cell = tableView.dequeueReusableCell(withIdentifier: "ContractTemplatePayment", for: indexPath) as! ContractTemplatePaymentTableViewCell
  88.  
  89. cell.paymentTitle.textColor = titleColor
  90.  
  91. cell.paymentTitle.text = self.langc.payment + " " + String(indexPath.row+1)
  92.  
  93. self.functions.enterValue(textfield: cell.amount, phText: self.langc.amount)
  94.  
  95. self.functions.enterValue(textfield: cell.shortText, phText: self.langc.shortText)
  96.  
  97. cell.add.tag = indexPath.section*1000 + indexPath.row
  98.  
  99. cell.add.addTarget(self, action: #selector(addPayment), for: .touchUpInside)
  100.  
  101. cell.separatorInset = .zero
  102.  
  103. return cell
  104. }
  105.  
  106. class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  107.  
  108. private let tableView = UITableView()
  109.  
  110. var articlesArray = [
  111. ArticleTemplate(articleName: "", clauses: ["A1"], payments: [Payment(amount: "", desc: "")]),
  112. ArticleTemplate(articleName: "", clauses: ["B1", "B2"], payments: [Payment(amount: "", desc: ""), Payment(amount: "", desc: "")])
  113. ]
  114.  
  115. override func viewDidLoad() {
  116. super.viewDidLoad()
  117.  
  118. self.view.backgroundColor = .white
  119.  
  120. self.tableView.backgroundColor = .clear
  121. self.tableView.delegate = self
  122. self.tableView.dataSource = self
  123. self.tableView.rowHeight = UITableViewAutomaticDimension
  124. self.tableView.register(ArticleTableViewCell.self, forCellReuseIdentifier: "ArtCellId")
  125. self.tableView.translatesAutoresizingMaskIntoConstraints = false
  126. self.tableView.tableFooterView = UIView()
  127.  
  128. self.view.addSubview(tableView)
  129. tableView.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor).isActive = true
  130. tableView.bottomAnchor.constraint(equalTo: self.view.layoutMarginsGuide.bottomAnchor).isActive = true
  131. tableView.leadingAnchor.constraint(equalTo: self.view.layoutMarginsGuide.leadingAnchor).isActive = true
  132. tableView.trailingAnchor.constraint(equalTo: self.view.layoutMarginsGuide.trailingAnchor).isActive = true
  133. }
  134.  
  135. func numberOfSections(in tableView: UITableView) -> Int {
  136. return self.articlesArray.count
  137. }
  138.  
  139. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  140. return UITableViewAutomaticDimension
  141. }
  142.  
  143. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  144. return 1
  145. }
  146.  
  147. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  148. let cell = tableView.dequeueReusableCell(withIdentifier: "ArtCellId", for: indexPath) as! ArticleTableViewCell
  149. cell.setData(article: self.articlesArray[indexPath.section])
  150. return cell
  151. }
  152. }
  153.  
  154. class ArticleTableViewCell: UITableViewCell, UITableViewDataSource, UITableViewDelegate {
  155.  
  156. let clausesTableView = UITableView()
  157. let clausesTableViewHeight: NSLayoutConstraint
  158. var clauses: [String]!
  159.  
  160. override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
  161. self.clausesTableViewHeight = clausesTableView.heightAnchor.constraint(equalToConstant: 0)
  162. super.init(style: style, reuseIdentifier: reuseIdentifier)
  163.  
  164. self.setupUI()
  165. self.clausesTableViewHeight.isActive = true
  166. }
  167.  
  168. required init?(coder aDecoder: NSCoder) {
  169. fatalError("init(coder:) has not been implemented")
  170. }
  171.  
  172. override func prepareForReuse() {
  173. super.prepareForReuse()
  174.  
  175. self.clauses = nil
  176. self.clausesTableView.dataSource = nil
  177. self.clausesTableView.delegate = nil
  178. }
  179.  
  180. private func setupUI() {
  181. self.selectionStyle = .none
  182.  
  183. self.clausesTableView.isScrollEnabled = false
  184. self.clausesTableView.register(UITableViewCell.self, forCellReuseIdentifier: "CellId")
  185. self.clausesTableView.translatesAutoresizingMaskIntoConstraints = false
  186. self.contentView.addSubview(clausesTableView)
  187. self.clausesTableView.topAnchor.constraint(equalTo: self.contentView.layoutMarginsGuide.topAnchor).isActive = true
  188. self.clausesTableView.bottomAnchor.constraint(equalTo: self.contentView.layoutMarginsGuide.bottomAnchor).isActive = true
  189. self.clausesTableView.leadingAnchor.constraint(equalTo: self.contentView.layoutMarginsGuide.leadingAnchor).isActive = true
  190. self.clausesTableView.trailingAnchor.constraint(equalTo: self.contentView.layoutMarginsGuide.trailingAnchor).isActive = true
  191. }
  192.  
  193. func setData(article: ArticleTemplate) {
  194. self.clauses = article.clauses
  195. self.clausesTableViewHeight.constant = CGFloat(44 * self.clauses.count)
  196. self.clausesTableView.delegate = self
  197. self.clausesTableView.dataSource = self
  198. }
  199.  
  200. func numberOfSections(in tableView: UITableView) -> Int {
  201. return 1
  202. }
  203.  
  204. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  205. return self.clauses.count
  206. }
  207.  
  208. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  209. let cell = tableView.dequeueReusableCell(withIdentifier: "CellId", for: indexPath)
  210. cell.textLabel?.text = self.clauses[indexPath.row]
  211. return cell
  212. }
  213. }
  214.  
  215. struct Payment {
  216. let amount: String
  217. let desc: String
  218. }
  219. struct ArticleTemplate {
  220. let articleName: String
  221. let clauses: [String]
  222. let payments: [Payment]
  223. }
Add Comment
Please, Sign In to add comment