One: The use of proxy transmission value, is the use of agents to communicate.
Interface file:
#import <Foundation/Foundation.h>
@protocol cdelegate <NSObject>
-(void) Change: (NSString *) name;
@end
. h file
@interface viewcontroller:uiviewcontroller<cdelegate>
. m file
-(Ibaction) PUSHBB: (ID) Sender {
Bviewcontroller *bc=[[bviewcontroller alloc]initwithnibname:@ "Bviewcontroller" Bundle:[nsbundle MainBundle];
bc.delegate=self;
[Self PRESENTVIEWCONTROLLER:BC animated:yes completion:nil];
}
Bviewcontroller file
. h file
#import "ViewController.h"
#import "Cdelegate.h"
@interface Bviewcontroller:viewcontroller
@property (Weak, nonatomic) Iboutlet Uitextfield *name;
@property (nonatomic,assign) id<cdelegate> delegate;
@property (nonatomic,copy) Ablock block;
-(Ibaction) POPBB: (ID) sender;
@end
. m file
-(Ibaction) POPBB: (ID) Sender {
[Self.delegate Change:self.name.text];
[Self dismissviewcontrolleranimated:yes completion:nil];
}
II: Block Pass Value
typedef void (^ablock) (NSString *str);
@property (nonatomic,copy) Ablock block;
-(Ibaction) POPBB: (ID) Sender {
[Self.delegate Change:self.name.text];
Self.block (Self.name.text);
[Self dismissviewcontrolleranimated:yes completion:nil];
}
-(Ibaction) PUSHBB: (ID) Sender {
Bviewcontroller *bc=[[bviewcontroller alloc]initwithnibname:@ "Bviewcontroller" Bundle:[nsbundle MainBundle];
bc.block=^ (NSString *str) {
SELF.ANAME.TEXT=STR;
};
[Self PRESENTVIEWCONTROLLER:BC animated:yes completion:nil];
}
Three: Notice
Nsdictionary *dic=[nsdictionary dictionaryWithObject:self.name.text forkey:@ "name"];
[[Nsnotificationcenter defaultcenter]postnotificationname:@ "Changetext" object:self userInfo:dic];
-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (changetext:) name:@ "Changetext" object: NIL];
}
iOS Pass value--proxy value, block pass value, Nsnotificationcenter pass value