traitCollectionDidChange don't trigger properly in Objective-C

850 Views Asked by At

I use traitCollectionDidChange in my swift classes to successfully trigger dark mode changes. Like this:

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    toggleDarkMode()
}

Works great. It triggers every time I switch between modes. But for my objective-c classes the delegate don't trigger when switching between dark and light mode. Code looks similar:

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
    [self toggleDarkMode];
} 

I can only get it to trigger by going out of the view, then back in again. Is there something I have missed in the objective-c code?

1

There are 1 best solutions below

0
On

I get it working calling super:

 - (void) traitCollectionDidChange: (UITraitCollection *) previousTraitCollection {
    [super traitCollectionDidChange: previousTraitCollection];
    [self toggleDarkMode];
}