Last active
May 22, 2020 18:35
-
-
Save 0xLeif/ba9f15927527eb16c41c94c33179cd0b to your computer and use it in GitHub Desktop.
TableView_DidSelectRow_Issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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