Skip to content

Instantly share code, notes, and snippets.

@0xLeif
Last active May 22, 2020 18:35
Show Gist options
  • Save 0xLeif/ba9f15927527eb16c41c94c33179cd0b to your computer and use it in GitHub Desktop.
Save 0xLeif/ba9f15927527eb16c41c94c33179cd0b to your computer and use it in GitHub Desktop.
TableView_DidSelectRow_Issue
import UIKit
import SwiftUIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.embed {
TableView().register(cells: [DataCell.self])
.shouldHighlightRowAtIndexPath { _ in true } // Needs to be true
.didSelectRowAtIndexPath {
print("Did Select: \($0)")
}
.append {
[
[DataValue(value: "First Value")]
]
}
}
}
}
struct DataValue {
let value: String
}
extension DataValue: CellDisplayable {
var cellID: String {
DataCell.ID
}
}
class DataCell: UITableViewCell {
let label = Label("")
}
extension DataCell: TableViewCell {
func configure(forData data: CellDisplayable) {
contentView.clear().embed {
label
}
}
func update(forData data: CellDisplayable) {
guard let data = data as? DataValue else {
return
}
label.text = data.value
}
static var ID: String {
"datacell"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment