通知

#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

 

posted @ 2016-06-28 21:27  阿法狗的世界  阅读(98)  评论(0)    收藏  举报