UI: not all subclasses of CopyableLabelTableViewCell have a detailTextLabel, so generalize

This commit is contained in:
Jason A. Donenfeld 2018-10-31 16:38:05 +01:00
parent 04993104b1
commit 56d827d04a
3 changed files with 13 additions and 1 deletions

View File

@ -6,6 +6,10 @@ import UIKit
class CopyableLabelTableViewCell: UITableViewCell {
var copyableGesture = true
var textToCopy: String? {
fatalError("textToCopy must be implemented by subclass")
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ -41,7 +45,7 @@ class CopyableLabelTableViewCell: UITableViewCell {
}
override func copy(_ sender: Any?) {
UIPasteboard.general.string = self.detailTextLabel?.text
UIPasteboard.general.string = textToCopy
}
override func prepareForReuse() {

View File

@ -311,6 +311,10 @@ class TunnelDetailTableViewKeyValueCell: CopyableLabelTableViewCell {
set(value) { detailTextLabel?.text = value }
}
override var textToCopy: String? {
return self.detailTextLabel?.text
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .value1, reuseIdentifier: TunnelDetailTableViewKeyValueCell.id)
}

View File

@ -441,6 +441,10 @@ class TunnelEditTableViewKeyValueCell: CopyableLabelTableViewCell {
valueTextField.spellCheckingType = .no
}
override var textToCopy: String? {
return self.valueTextField.text
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}