-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMNodeCell.swift
More file actions
38 lines (32 loc) · 1.01 KB
/
MMNodeCell.swift
File metadata and controls
38 lines (32 loc) · 1.01 KB
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
//
// MMNodeCell.swift
// MMTreeTablViewExample
//
// Created by JefferyYu on 2022/2/26.
//
import UIKit
class MMNodeCell: UITableViewCell {
public var customerView: UIView? {
didSet {
if customerView != oldValue {
handleRowChanged(oldValue: oldValue)
}
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = .clear
selectionStyle = .none
}
required init?(coder: NSCoder) { super.init(coder: coder) }
// MARK: Updating
private func handleRowChanged(oldValue: UIView?) {
// Remove old
oldValue?.removeFromSuperview()
// Add new
if let view = customerView {
view.removeFromSuperview()
contentView.addSubview(view, pinningEdges: .all, withInsets: UIEdgeInsets(top: 0, left: CGFloat(indentationLevel) * indentationWidth, bottom: 0, right: 0))
}
}
}