zoukankan      html  css  js  c++  java
  • iOS学习之Delegate设计模式

    In review, these are the steps for setting up the delegate pattern between two objects, where object A is the delegate for object B and object B will send out the messages:

    1. Define a delegate @protocol for object B.

    2. Give object B a property for that delegate protocol.

    3. Make object B send messages to its delegate when something interesting happens, such as the user pressing the Cancel or Done buttons, or when it needs a piece of information.

    4. Make object A conform to the delegate protocol. It should put the name of the protocol in its @interface line and implement the methods from the protocol.

    5. Tell object B that object A is now its delegate. 

    tips:

    1.if screen A(object A) launches screen B(object B) then you don’t want screen B to know too much about the screen that invoked it (A).

    2.Using a delegate helps to abstract the dependency from screen B on screen A. 

    3.Anytime you want one part of your app to notify another part about something, usually in order to update the screen, you want to use delegates. 

    4.if screen A opens screen B, then A can give B the data it needs. You simply make a property for this data on screen B and then screen A puts something into this property right before it makes screen B visible.To pass data back from B to A you would use a delegate. 

  • 相关阅读:
    USACO 5.5 Twofive
    USACO 5.4 Telecowmunication
    USACO 5.4 Character Recognition
    BZOJ 1001: [BeiJing2006]狼抓兔子
    USACO 5.4 Canada Tour
    USACO 5.3 Big Barn
    USACO 5.3 Network of Schools
    USACO 5.3 Window Area
    2017辽宁冬令营-4.蚂蚁
    2017辽宁冬令营-3.斐波那契
  • 原文地址:https://www.cnblogs.com/guitarandcode/p/5447545.html
Copyright © 2011-2022 走看看