Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CustomView.swift
- // TableViewNotification
- //
- // Created by Mihai Muntean on 18/07/2019.
- // Copyright © 2019 Mihai Muntean. All rights reserved.
- //
- import UIKit
- protocol CustomViewProtocol: AnyObject {
- func but2pressed(indexPath: IndexPath)
- }
- class CustomView: UIView, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet var customView: UIView!
- @IBOutlet weak var tableView: UITableView!
- weak var delegate: CustomViewProtocol?
- override init(frame:CGRect) {
- super.init(frame:frame)
- configureUI()
- }
- required init?(coder aDecoder:NSCoder) {
- super.init(coder:aDecoder)
- }
- func configureUI(){
- Bundle.main.loadNibNamed("CustomView", owner: self, options: nil)
- customView.bounds = self.bounds
- customView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
- addSubview(customView)
- tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 10
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
- cell.textLabel?.text = "Row \(indexPath.row)"
- return cell
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let ip: IndexPath! = indexPath
- delegate?.but2pressed(indexPath: ip)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement