What is the purpose of an iOS delegate?

前端 未结 11 1520
野性不改
野性不改 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:38

    Delegate is an important design pattern for iOS app.All apps directly or behind the hood use this delegate pattern. Delegate design pattern allows an object to act on behalf of another. If we are working with tableview then there are "tableViewDelegate" and "tableViewDataSource". But what this means

    Suppose you have a tableview. now some major concern for this. 1.what is the datasource(the data that will appear in table view) for this tableview? 2.How many row for table view etc. delegate design pattern solve these question using another object as the provider or the solver of these question. An object mark himself to the table view and ensure the table view that "Yes i am the man who can assist you" by marking himself as the delegate to the table view .Thanks

提交回复
热议问题