Suppose I have ViewController A, its viewModel AVM. A has a containerView, which is ViewController B and its viewModel BVM. A has reference of B and AVM has a reference of BVM as its child View Model.
And I have a C, which is a manager class controls the behaviour of B, calling functions in B such as setSDImage(url) from B.
B has a UIImageView and has setSDImage(url) function with a callback. A has a button, when button pressed, it should trigger the setSDImage(url) for B.
So the problems is: Press button from A, goes to AVM, then AVM contacts C telling it to do some work to B, now, C has to get a reference of B since the function call is setSDImage(url) which is UI layer. Also, the callback needs to be implemented in B as well, that's why I don't know how to get this work in BVM rather than B.
So, questions in this case:
1, manager class C, controls behaviour of B. How does AVM contact C without passing reference of B? (since VM don't want to know about ViewControllers/views)
2, should manager class C controls B or BVM? I make it controls B instead of BVM because a) the set image function has to be done in UILayer which is B. b) the callback needs to be implemented in UILayer?
Aucun commentaire:
Enregistrer un commentaire