configurationUpdateHandler
A block for handling updates to the cell’s configuration using the current state.
Declaration
@MainActor @preconcurrency var configurationUpdateHandler: UITableViewCell.ConfigurationUpdateHandler? { get set }Discussion
A configuration update handler provides an alternative approach to overriding updateConfiguration(using:) in a subclass. Set a configuration update handler to update the cell’s configuration using the new state in response to a configuration state change:
cell.configurationUpdateHandler = { cell, state in
var content = cell.defaultContentConfiguration().updated(for: state)
content.text = "Hello world!"
if state.isDisabled {
content.textProperties.color = .systemGray
}
cell.contentConfiguration = content
}Setting the value of this property calls setNeedsUpdateConfiguration(). The system calls this handler after calling updateConfiguration(using:).
In iOS 18 and later, UIKit supports automatic trait tracking inside this closure for traits from this cell’s traitCollection. For more information, see Automatic trait tracking.
This closure supports automatic observation tracking. For more information, see Updating views automatically with observation tracking.