A small but very powerful API addition in iOS 15 is the new configurationUpdateHandler property on UICollectionViewCell, UITableViewCell, UITableViewHeaderFooterView, and even UIButton.
developer.apple.com/documentation/…
TL;DR: you can set a closure which is called anytime the view's state changes.

If you're familiar with the updateConfiguration(using state:) method introduced last year in iOS 14, this is a closure-based version of it — so you don't need a subclass just to override that anymore!
This handler makes it really easy to customize the configuration & appearance of your cells/headers/buttons for different states, directly inline.

It's a great place to apply a new configuration, but you can update any other properties of the cell/view in the handler, too!
The best part is that this handler is guaranteed to run before the cell/view first displays. So if you want, you can do _all_ your configuration of the cell/view _inside_ the handler — meaning you write a single code path, which runs for both initial setup and subsequent updates!
Since it's a closure, you can capture references in it too (though be careful about what you retain).

And to run the handler again anytime (e.g. to update the view when a captured reference changes), just call setNeedsUpdateConfiguration() to invalidate the view's configuration!
For a refresher on updateConfiguration(using state:), setNeedsUpdateConfiguration(), and other configuration-related APIs, check out the Modern Cell Configuration video from WWDC20 last year: developer.apple.com/videos/play/ww…
And to learn about all the new UIButton configuration APIs introduced this year in iOS 15, including examples of how you can use the configurationUpdateHandler with buttons, watch the "Meet the UIKit button system" video: developer.apple.com/wwdc21/10064

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Tyler Fox

Tyler Fox Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @smileyborg

13 Jun
iOS 15 introduces a new way for you to conveniently update content displayed in existing cells in UICollectionView and UITableView: reconfigure.

When and why should you use reconfigure? How is it different from reloading an item or row?

Let’s dive in with a quick thread.
You can think of reconfigure as a lighter-weight version of reload.

Reload: replaces the existing cell with a new cell.

Reconfigure: allows you to directly update the existing cell.

Because reconfigure doesn’t request/create a new cell, it’s significantly more efficient!
How does reconfigure work?

For each item/row you reconfigure:

- If there’s no existing cell, it’s a no-op!
- Otherwise, the collection/table view calls your cell provider again, but with special behavior to return the *existing* cell when you dequeue one for that index path.
Read 10 tweets
16 Oct 20
It’s a good question. There are a number of reasons why these properties are marked as “to be deprecated” in a future release.

Here’s a short thread to explain some of those.
For starters, there’s well over a decade of implementation behind these properties and the different cell styles, with layers upon layers of complexity to preserve binary compatibility with all the apps using them. (Old apps in the App Store need to keep working without updates!)
Unfortunately, because these built-in cell textLabel/imageView properties expose the entire API surface of UILabel/UIImageView, that means apps are doing all sorts of unexpected things to these views that weren’t intended to be supported (but aren’t explicitly disallowed, either)
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(