通知
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textFieldOne;
@property (weak, nonatomic) IBOutlet UITextField *textFieldTwo;
- (IBAction)btnClick:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *button;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tongzhi:) name:@"tongzhi" object:nil];
}
- (IBAction)btnClick:(id)sender {
NSDictionary * dict=[NSDictionary dictionaryWithObjectsAndKeys:self.textFieldOne.text,@"textOne",self.textFieldTwo.text,@"textTwo", nil];
//创建一个通知
NSNotification * notification=[NSNotification notificationWithName:@"tongzhi" object:nil userInfo:dict];
//通知中心发出通知
[[NSNotificationCenter defaultCenter]postNotification:notification];
}
-(void)tongzhi:(NSNotification *)text
{
NSString * str=[NSString stringWithFormat:@"%@-->%@",text.userInfo[@"textOne"],text.userInfo[@"textTwo"]];
[self.button setTitle:str forState:UIControlStateNormal];
}
@end

浙公网安备 33010602011771号