Skip to content

Add view controllers to the container hierarchy, and implement didMoveToWindow hook.#2

Open
carllindberg wants to merge 1 commit intoCollect3:masterfrom
carllindberg:ViewControllerContainers
Open

Add view controllers to the container hierarchy, and implement didMoveToWindow hook.#2
carllindberg wants to merge 1 commit intoCollect3:masterfrom
carllindberg:ViewControllerContainers

Conversation

@carllindberg
Copy link

This pull request has a couple of related changes, needed to make things work in one application I'm working on.

First, UIViewControllers are UIAppearanceContainers, but were not being added to the container list, so a few of my appearance proxies were not being applied since they were never matched. I did that by mixing in the view controllers in the container list right after the view it was controlling.

Additionally, it is best to add the UIPopoverController at the end, if applicable. I don't know of any public API to do that, and we have a private mechanism to determine the popover for at least most of the popovers in our app, so that is what I used locally. For this, I just added a comment in the right spot to add the popover if it can be determined.

We also had a situation where views were added into a container view (thus getting all of the willMoveToSuperview: calls at this point), but only later was the container added to a superview itself. In this situation, the hierarchy changes greatly, meaning more appearance proxies should come into play, but there was nothing to catch this, I don't think. I added an implementation of didMoveToWindow, to re-apply the hierarchy-based appearance proxies again if necessary. This is particularly necessary in the case of UITableViewCells, which are often configured before being returned to the UITableView from the data source methods, and which only get added as a subview later on.

This seems to catch the conditions we needed, though I am a little concerned that any UIBar[Button]Item appearance proxies are never getting applied. I have not yet found a place where that is hurting us, but that might require some additional work if so. Also, in the core "apply" method, for some particular UISegmentedControls I had to add a "[view setNeedsLayout]; [view layoutIfNeeded]" right after applying the appearance proxies in order to get the font to redisplay right (it was displaying with the old font until the user clicked on it). That may have been something particular to our app so I did not include that code here.

… container-based settings use them in their UIAppearanceContainer list. Add a note for the correct place to add a UIPopoverController, if possible. Had to add an additional place where the container-based appearances are applied, as it is possible for a view to be added to a superview first, and only later have the superview added to another superview (changing the potential hierarchy), and willMoveToSuperview: will not be called in that scenario. Used didMoveToWindow as a hook to apply additional hierarchy-based appearance calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments