lundi 30 mars 2015

Which is the better way to communicate between two views?

One of our our project requires a simple custom keyboard control that will be reused throughout the project's many views and possibly future projects as well.


A question was posed:


If we know that the keyboard control's sole purpose is to provide the user a way to input data to modify a single UITextField or UILabel is it:


a) better to pass a reference to that UITextField to the CustomKeyboardView and let that view handle the modification of the textfield's text inside of it's class or:


b) write a delegate for returning the values from the CustomKeyboardView and make the parent viewController handle receiving callbacks from the keyboard and setting the correct value of the UITextField or:


c) do it using some other pattern?


It is worth noting that the code for writing text to the textfield is a bit more involved than simply passing raw characters, it compares the value that is already in the textfield and passes the character according to that state.


Aucun commentaire:

Enregistrer un commentaire