Skip to content

Commit 63d34ee

Browse files
committed
still playing with configurations
1 parent 7209c8d commit 63d34ee

File tree

20 files changed

+795
-2
lines changed

20 files changed

+795
-2
lines changed

bk2ch08p409BareContentConfiguration/BareContentConfiguration/ViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct MyContentConfiguration : UIContentConfiguration {
3838
return MyContentView(self)
3939
}
4040
func updated(for state: UIConfigurationState) -> MyContentConfiguration {
41+
print("updated")
4142
return self
4243
}
4344
}
@@ -50,7 +51,7 @@ class ViewController: UIViewController {
5051
// test harness
5152
var config = MyContentConfiguration()
5253
config.text = "Hello, world"
53-
let v = config.makeContentView()
54+
let v = MyContentView(config)
5455
v.frame = CGRect(x: 100, y: 100, width: 200, height: 100)
5556
v.backgroundColor = .yellow
5657
self.view.addSubview(v)

bk2ch08p409TableContentConfiguration/TableContentConfiguration/ViewController.swift

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class MyContentView : UIView, UIContentView {
1515
self.addSubview(self.label)
1616
label.textAlignment = .center
1717
label.translatesAutoresizingMaskIntoConstraints = false
18+
label.highlightedTextColor = .white
19+
// that works, so it is not an example of why you'd need to implement updatedForState
1820
NSLayoutConstraint.activate([
1921
label.topAnchor.constraint(equalTo: self.topAnchor, constant: 10),
2022
label.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -10),
@@ -38,6 +40,9 @@ struct MyContentConfiguration : UIContentConfiguration {
3840
return MyContentView(self)
3941
}
4042
func updated(for state: UIConfigurationState) -> MyContentConfiguration {
43+
if let state = state as? UICellConfigurationState {
44+
print(state.isSelected, state.isHighlighted, state.traitCollection)
45+
}
4146
return self
4247
}
4348
}
@@ -56,7 +61,7 @@ class ViewController: UITableViewController {
5661
}
5762

5863
let cellID = "cell"
59-
var which = 3
64+
var which = 2
6065
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
6166
let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
6267
switch which {
@@ -88,5 +93,13 @@ class ViewController: UITableViewController {
8893
}
8994
return cell
9095
}
96+
97+
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
98+
if tableView.indexPathForSelectedRow == indexPath {
99+
tableView.deselectRow(at:indexPath, animated:false)
100+
return nil
101+
}
102+
return indexPath
103+
}
91104
}
92105

0 commit comments

Comments
 (0)