Sharing and processing of data between different Viewcontroller
-
Using the proxy method, the sub-Viewcontroller design the agent protocol, and define the Protocol interface, the parent Viewcontroller implements the Protocol interface, and implements the child view controller to update the related data to the parent view when exiting.
-
Using the iOS messaging mechanism, the parent Viewcontroller registers the message, and the child Viewcontroller sends the message, triggering the parent Viewcontroller message processing
-
Using database as the intermediate storage medium, the sub-viewcontroller the state data into DB, and the parent Viewcontrller gets the data from the DB to update the view
-
Nsdefault storage with iOS;
-
Implementing the storage of intermediate data by defining global variables in Appdelegate
Note:
First, use a reverse proxy example: Between two viewcontroller, let the view two exit when the view one owns the color of the view two;
Here to solve two problems: first, the view of the second exit, let the view of the color of their own change, there is no doubt that the view of the class needs to add a method;
This method can only be the view and the design of the proxy protocol, and define the Protocol interface; Second, the value problem, before entering the second view, the second view needs to be
is set to view one, for the subsequent view and the next call to the event, the agent to invoke the agent has implemented the method to pave the way;
Compare the forward-to-agent approach: This is in the context of the UI in order to execute the case, in the OC phase encountered person class two class, we design the association
The definition of the Protocol interface is person, then let the class implementation of the person object to add to the class directory of the method;
Second: Appdelegate Here is a single example of implementation runloop in the UI, for a singleton, we can write a sharedinstance ourselves; notice and self
Write a single example class, when the value is passed, appdelegate,sharedinstance need to have the data to be passed the field properties;
Third: This involves the agreement @protocal first in OC not polymorphic, multi-inheritance, through the @peotocal way to achieve polymorphism; Agreement who will do, who is real
Now, its corresponding header file with angle brackets to add the protocol name, and then introduce the agent, the Boss class in their own header file to do this Protocol errand agent field
property, and the protocol header file is introduced in the Boss class implementation file (and in the proxy class because the header file angle bracket introduces the protocol, so its corresponding implementation file does not need to add
protocol header file);
How data is transferred between iOS app view