Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. //
  2. // CustomView.swift
  3. // TableViewNotification
  4. //
  5. // Created by Mihai Muntean on 18/07/2019.
  6. // Copyright © 2019 Mihai Muntean. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. protocol CustomViewProtocol: AnyObject {
  12. func but2pressed(indexPath: IndexPath)
  13. }
  14.  
  15. class CustomView: UIView, UITableViewDelegate, UITableViewDataSource {
  16. @IBOutlet var customView: UIView!
  17. @IBOutlet weak var tableView: UITableView!
  18.  
  19. weak var delegate: CustomViewProtocol?
  20.  
  21. override init(frame:CGRect) {
  22. super.init(frame:frame)
  23.  
  24. configureUI()
  25. }
  26.  
  27. required init?(coder aDecoder:NSCoder) {
  28. super.init(coder:aDecoder)
  29. }
  30.  
  31. func configureUI(){
  32. Bundle.main.loadNibNamed("CustomView", owner: self, options: nil)
  33. customView.bounds = self.bounds
  34. customView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  35.  
  36. addSubview(customView)
  37.  
  38. tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
  39. }
  40.  
  41. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  42. return 10
  43. }
  44.  
  45. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  46. let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
  47. cell.textLabel?.text = "Row \(indexPath.row)"
  48.  
  49. return cell
  50. }
  51.  
  52. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  53. let ip: IndexPath! = indexPath
  54. delegate?.but2pressed(indexPath: ip)
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement