Value passing between iOS pages: One-case value passing, block Value passing, and iosblock
There are a lot of values passed between ios pages. The front side has already shared the attribute transfer value and the proxy transfer value. Today we mainly talk about the single-case transfer value and block transfer value.
Single case transfer value: Singleton mode is a common development mode. Singleton is obtained from the same object no matter when the object is initialized in the entire program, objects have the same attributes, so they can be used to pass values.
The block value is similar to the proxy value. It is mainly used to pass the value to the first page on the second page. The specific steps for transferring the block value are as follows:
On the second page:
1. Declaration: block typedef void (^ SendMessagerBlock) (NSString * str );
2. Creation Method:-(void) sendMessage :( SendMessagerBlock) block;
3. Declare attributes: @ property (nonatomic, copy) SendMessagerBlock;
4. Implementation Method:-(void) sendMessage :( SendMessagerBlock) block {
Self. block = block;
}
5. Call block: self. block (self. textField. text );
On the first page
6. Call method: [seconVC sendMessage: ^ (NSString * str ){
WeakSelf. textField. text = str;
}];