Handle cell reuse in showing delete buttons in red
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
e7a1f142fb
commit
90af773fef
|
@ -198,7 +198,7 @@ extension TunnelDetailTableViewController {
|
|||
// Delete configuration
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewButtonCell.id, for: indexPath) as! TunnelDetailTableViewButtonCell
|
||||
cell.buttonText = "Delete tunnel"
|
||||
cell.button.tintColor = UIColor.red
|
||||
cell.hasDestructiveAction = true
|
||||
cell.onTapped = { [weak self] in
|
||||
guard let s = self else { return }
|
||||
s.showConfirmationAlert(message: "Delete this tunnel?", buttonTitle: "Delete", from: cell) { [weak s] in
|
||||
|
@ -336,12 +336,18 @@ class TunnelDetailTableViewButtonCell: UITableViewCell {
|
|||
get { return button.title(for: .normal) ?? "" }
|
||||
set(value) { button.setTitle(value, for: .normal) }
|
||||
}
|
||||
var hasDestructiveAction: Bool {
|
||||
get { return button.tintColor == UIColor.red }
|
||||
set(value) { button.tintColor = value ? UIColor.red : buttonStandardTintColor }
|
||||
}
|
||||
var onTapped: (() -> Void)? = nil
|
||||
|
||||
let button: UIButton
|
||||
var buttonStandardTintColor: UIColor
|
||||
|
||||
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
|
||||
button = UIButton(type: .system)
|
||||
buttonStandardTintColor = button.tintColor
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
contentView.addSubview(button)
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -364,5 +370,6 @@ class TunnelDetailTableViewButtonCell: UITableViewCell {
|
|||
super.prepareForReuse()
|
||||
buttonText = ""
|
||||
onTapped = nil
|
||||
hasDestructiveAction = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ extension TunnelEditTableViewController {
|
|||
if (field == .deletePeer) {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewButtonCell.id, for: indexPath) as! TunnelEditTableViewButtonCell
|
||||
cell.buttonText = field.rawValue
|
||||
cell.button.tintColor = UIColor.red
|
||||
cell.hasDestructiveAction = true
|
||||
cell.onTapped = { [weak self, weak peerData] in
|
||||
guard let peerData = peerData else { return }
|
||||
guard let s = self else { return }
|
||||
|
@ -512,12 +512,18 @@ class TunnelEditTableViewButtonCell: UITableViewCell {
|
|||
get { return button.title(for: .normal) ?? "" }
|
||||
set(value) { button.setTitle(value, for: .normal) }
|
||||
}
|
||||
var hasDestructiveAction: Bool {
|
||||
get { return button.tintColor == UIColor.red }
|
||||
set(value) { button.tintColor = value ? UIColor.red : buttonStandardTintColor }
|
||||
}
|
||||
var onTapped: (() -> Void)? = nil
|
||||
|
||||
let button: UIButton
|
||||
var buttonStandardTintColor: UIColor
|
||||
|
||||
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
|
||||
button = UIButton(type: .system)
|
||||
buttonStandardTintColor = button.tintColor
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
contentView.addSubview(button)
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -540,6 +546,7 @@ class TunnelEditTableViewButtonCell: UITableViewCell {
|
|||
super.prepareForReuse()
|
||||
buttonText = ""
|
||||
onTapped = nil
|
||||
hasDestructiveAction = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue