开发者

Reusing view/view controllers?

I have开发者_C百科 a view and its view controller. They get the job done and work as I want to. One of the functionalities is when the user taps the view, something gets added to it.

I'm adding new features to my app and I could reuse my view and its view controller BUT when the user taps on the view, I don't want anything to be added. What could be a good approach? Should I configure my controller depending on who is calling it? This then implies that I need to check throughout my code how my view and view controller are being used (ex: if (isAllowedToAdd) {...} )

This feels messy and I think I'm missing the point of MVC. Any suggestions?


Well, I think it depends on the "something" that gets added to your view. Maybe a good compromise would be to separate all common code/functionalities in a parent class from which each controller would inherit?

You can also set a custom init method that would take a parameter defining whether add is allowed or not. Then just enable/disable the whole tap gesture recognizer (I guess you have one) based on this parameter. Thus, you would not have to check any flag throughout your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜