Reusing view / view controllers?

I have a view and its controller. They do their job and work the way I want. One of the functions is when the user removes the view, adds something to it.

I am adding new features to my application and I can reuse my view and its view controller. BUT, when a user clicks on a view, I don’t want something to be added. What could be a good approach? Do I have to configure my controller depending on who calls it? This means that I need to check throughout my code how my view and view controller is being used (for example: if (isAllowedToAdd) {...})

It seems dirty, and I think I am missing the MVC point. Any suggestions?

+4
source share
1 answer

Well, I think it depends on what is added to your opinion. Perhaps a good compromise would be to separate all the common codes / functionality in the parent class from which each controller is inherited?

You can also set your own initialization method, which will take a parameter that determines whether adding is allowed or not. Then just turn on / off the whole gesture recognizer (I think you have it) based on this parameter. This way you will not need to check the flag in all code.

0
source

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


All Articles