What is the purpose of an iOS delegate?

前端 未结 11 1546
野性不改
野性不改 2020-12-18 23:22

I understand what a delegate does in iOS, and I\'ve looked at sample code, but I\'m just wondering about the advantages of this type of encapsulation (as opposed to includin

11条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 23:30

    The class marked as delegate takes the responsibilities to handle the callbacks sent while some event occurs. For example, in case of UITextField, there are some methods called when some events occurs like editing started, editing ended, character typed etc. These methods will already be defined in the protocol. We will have to assign delegate for that i.e. which class is going to handle these events.

提交回复
热议问题