Objective
In an explanation of the way iOS passes through the proxy reverse value, analysis of how to use the proxy mode to reverse the value, in fact, there are other ways, such as notification, block, compared to agents, I personally think it is simpler, but need to deal with the details of the problem, such as block circular reference. Or use the previous case, the use of block to achieve, block the basic knowledge of this article no longer repeat.
I. Writing specifications
Block pass value, it should be noted that, who is the value of the need to define block, the capture only need to pass the block to pass the party, and processing the captured values.
Pass Value Square
1. Define block for passing values
2, declare a block attribute above, the specific implementation of this property needs to capture the party to pass in
3, when the need to pass the value of the call block to complete the transfer value
Capture side
1, pass a block to pass the value square
2. Capture the passed value in block and handle the captured value according to the requirement
Second, block and reverse transfer value
Or that sentence no Code, no BB, the case results are as follows:
Reverse Transfer value
Third, the realization step
1, transfer value side
. h file
/**
* Type customization
/typedef void (^returnvalueblock) (NSString *strvalue);
@interface Nextviewcontroller:uiviewcontroller
/**
* Declares a Returnvalueblock property, which is the interface that gets the value of the transfer
.
@property (nonatomic, copy) Returnvalueblock Returnvalueblock;
@end
=================================================================
//.m file
#import " NextViewController.h "
@interface nextviewcontroller ()
@property (weak, nonatomic) Iboutlet Uitextfield * Inputtext;
-(Ibaction) Back: (ID) sender;
@end
@implementation Nextviewcontroller
-(void) viewdidload {
[super viewdidload];
Self.navigationItem.title = @ "Second interface";
}
/**
* Return to previous interface
* *
@param sender button/
-(ibaction) Back: (ID) Sender {
NSString * InputString = Self.inputText.text;
if (self.returnvalueblock) {
//send its own value out, complete the transfer value
self.returnvalueblock (inputstring);
}
[Self.navigationcontroller Popviewcontrolleranimated:yes];
}
@end
2, the capture side
. m file
#import "ViewController.h"
#import "NextViewController.h"
@interface Viewcontroller ()
@ Property (weak, nonatomic) Iboutlet Uilabel *nextpassedvalue;
-(Ibaction) Next: (ID) sender;
@end
@implementation Viewcontroller
-(void) viewdidload {
[super Viewdidload];
}
Click the button to jump to the second interface
-(ibaction) Next: (ID) Sender {
Nextviewcontroller *NVC = [[Nextviewcontroller alloc]init];
Assignment block and assigns the captured value to Uilabel
nvc.returnvalueblock = ^ (NSString *passedvalue) {
Self.nextPassedValue.text = Passedvalue;
};
[Self.navigationcontroller PUSHVIEWCONTROLLER:NVC animated:yes];
}
@end
Summarize
The above is the entire content of this article, I hope the content of this article for your iOS developers can help, if you have questions you can message exchange.