How to transfer the value of iOS (learning) interface
Block:
Method of implementing interface value 1.block:
The realization of the interface value, all from the second boundary to the first interface to pass the value: the first block
first). the second interface Secondviewcontroller declares a set method
DECLARE block
@property (nonatomic,copy) void (^change) (Uicolor *color);
Second ). In the . M File implementation
ways to implement block
_callback ([Uicolor redcolor]);//Note the reason why this is _callback is the implementation of the get method, the default _callback
last) bring back to Firstviewcontroller with a second view controller
Implement the method written in block to pass to Firstviewcontroller
[SV setcallback:^ (Uicolor *color) {
Self.view.backgroundColor = color;
}];
Notification Center:
Method of implementing the interface Value 2. Notification Center:
FIRST). Register the Observer, then jump to the second interface, broadcast in the second interface, implement the method of registration, change the color of the first page
by notifying the Hub method first register an observer in Firstviewcontroller
1. Registration
Register an observer self in the notification
[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (notification) name:@ "ChangeColor" object: NIL];
2. second broadcast in Secondviewcontroller
Broadcasting
[[Nsnotificationcenter defaultcenter]postnotificationname:@ "ChangeColor" object:nil];
3. Find the previous color
-(void) notification{
Self.view.backgroundColor = [Uicolor Bluecolor];
}
Agent
Method of implementing Interface Value 3: Agent
First of all
from the second boundary, we use the proxy for the first interface to pass a value. The second interface is the agent, the first to develop a protocol
The essence of a protocol is a list of methods
@protocol protocal <NSObject>
-(void) Changebackcolor: (Uicolor *) color;
@end
Write a method in the agreement that rewards the person who complies with the agreement
Then tell the description to implement the agent as long as it meets the following
@property (nonatomic,assign) id<protocal> delegate;
Implemented in . M files, used to give a party to a compliance agreement
Secondly:
Compliance, the party adhering to the agency agreement must first comply with the agreement
And then get the award from the Agreement makers.
-(void) Changebackcolor: (Uicolor *) color
{
Self.view.backgroundColor = color;
}
4. The method is passed to the previous view controller by obtaining the previous view controller and then changing the contents of it, because the view controller is used in the form of a multiple page jump and then access is accessed by the array, the implementation of the method Secondviewcontroller
nsarray *arr =self. Navigationcontroller. Viewcontrollers;
uiviewcontroller *s = [arr objectatindex:0];
S. View. BackgroundColor = [uicolorredcolor];
[self. Navigationcontroller popviewcontrolleranimated:YES];
5.kvo
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS learning (method of interface transfer)