Multilevel child view controllers where delegation becomes a nightmare - how should they communicate with each other?

This is a serious problem for me right now. Working on a code base with multi-level children’s dispatcher presentations about 4-5 layers in size is an application for tablets with a very high degree of isolation between viewcontrollers dispatchers. The 5th level child view manager wants to send a message to the top level view manager to show the modal. Level 4 and level 3 have different messages, so basically now I have 4 protocols, and it’s quite difficult to send messages from such child view controllers nested in depth in the ancestor view controller. Is there an easier way to do this?

We thought about using NSNotification, but we didn’t particularly like it because of the complexity of its debugging and subscription, which is not an explicit dependency within our control. We also thought about using a singleton, but statics and singletones are evil (right?) And cause problems around state and concurrency.

Any help is appreciated. I also understand that I understand that this is a slightly open-ended question, based on design, but it has a very specific use case (for example, described above).

+4
source share
1 answer

An interesting question, but I think we need some tips, such as a circuit.
First thought - why do you need to add an embedded child? could you manage a simple stack and one vc container? It seems that it’s not right how you manage your venture capitalists. If they need to be notified of changes in the model, it should only be visible to catch them, others will appear in viewWill / Did /, you can again request fresh data. If you need to tell each VC about their status, I think you should change your hierarchy.
I present a Container VC with a stack or set of VCs and a visible VC. This Container will manage the exchange of information. As rdelmar said, this seems like a really high degree of grip. You must reconsider the path that only sees the connection between the container and the visible VC, others can update their data until they appear.

0
source

Source: https://habr.com/ru/post/1494366/


All Articles