configurationUpdateHandler
A block for handling updates to the cell’s configuration using the current state.
Declaration
@property (nonatomic, copy) UICollectionViewCellConfigurationUpdateHandler configurationUpdateHandler;Discussion
A configuration update handler provides an alternative approach to overriding updateConfigurationUsingState: 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 setConfigurationUpdateHandler:^(UICollectionViewCell *cell, UICellConfigurationState *state) {
UIListContentConfiguration *content = [[UIListContentConfiguration cellConfiguration] updatedConfigurationForState:state];
[content setText: @"Hello world!"];
if (state.isDisabled) {
[content.textProperties setColor:[UIColor systemGrayColor]];
}
[cell setContentConfiguration:content];
}];Setting the value of this property calls setNeedsUpdateConfiguration(). The system calls this handler after calling updateConfigurationUsingState:.
In iOS 18 and later, UIKit supports automatic trait tracking inside this block 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.