forked from psharanda/Atributika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnippetsViewController.swift
56 lines (43 loc) · 1.64 KB
/
SnippetsViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by Pavel Sharanda on 21.02.17.
// Copyright © 2017 Pavel Sharanda. All rights reserved.
//
import UIKit
class SnippetsViewController: UIViewController {
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: CGRect(), style: .plain)
tableView.delegate = self
tableView.dataSource = self
#if swift(>=4.2)
tableView.rowHeight = UITableView.automaticDimension
#else
tableView.rowHeight = UITableViewAutomaticDimension
#endif
tableView.estimatedRowHeight = 50
return tableView
}()
private var snippets = allSnippets()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tableView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tableView.frame = view.bounds
}
}
extension SnippetsViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return snippets.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellId = "CellId"
let cell = tableView.dequeueReusableCell(withIdentifier: cellId) ?? UITableViewCell(style: .default, reuseIdentifier: cellId)
cell.textLabel?.attributedText = snippets[indexPath.row]
cell.textLabel?.numberOfLines = 0
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
}