Is delegation the preferred way to do this?

I have a subclass of UIViewController that allows the user to add a new model object, in this case a bank account. I called the AddBankAccountViewController view controller. The user can enter the account number, account label and account bank, but all this is done in separate view controllers.

I use delegation to let AddBankAccountViewController know that the user has changed values. As a result, AddBankAccountViewController now complies with 3 custom protocols (e.g. EditAccountNumberViewControllerDelegate, etc.), and this may be even more in the future.

My question is: is this done correctly, or is there a better way (e.g. direct link from view controllers to AddBankAccountViewController)?

+3
source share
2 answers

The delegation is in order. You might want to summarize related methods in a common (possibly optional) protocol. Or you can use the target / action template, but delegation is what you want most of the time.

+1
source

, BankAccount , BankAccount ( , viewDidAppear:). , .

+2

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


All Articles