美文网首页iOS
iOS通知中心

iOS通知中心

作者: MWY | 来源:发表于2015-11-20 11:34 被阅读342次

有关的类

  1. NSNotification
  2. NSNotificationCenter
NSNotification

NSNotification实例将对象发送到NSNotificationCenter,并由NSNotificationCenter将通知发送出去

首先需要注册观察这对象:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(notifi) name:@"Maweiyi" object:nil];
}

发送通知:


- (IBAction)btnClick:(id)sender {
    
    
    NSString *string = @"This is a good man";
    NSNotification *notification = [[NSNotification alloc] initWithName:@"Maweiyi" object:string userInfo:nil];
    
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}

- (void)notifi {
    NSLog(@"我接收到通知了1");
}

相关文章

  • IOS通知中心

    通知中心(NSnotificationCenter): 由发送者1或者多个发送者n 通过发送一个通知到通知中心,接...

  • iOS - 通知中心

    通知中心:NSNotificationCentereg:农村大喇叭发送广播 条件:在大喇叭广播之前要有村民(对象-...

  • iOS 通知中心

    不要随随便便就是用通知,不懂的话对性能影响挺大的.虽然用起来很方便. 下边是理论知识: 即使在适合使用通告的场合下...

  • iOS 通知中心

    What is NSNotificationCenter? NSNotificationCenter是一种一对多的...

  • iOS通知中心

    http://potter528.bj.bdysite.com 如果播放器播放完毕后通知中心通知对象,执行方法选择...

  • iOS通知中心

    有关的类 NSNotification NSNotificationCenter NSNotification N...

  • iOS 通知 与 通知中心

    iOS 通知中心:自己实现了一套消息机制,可以跨页面调用 类似Unity的SendMessage,是订阅、发布者模...

  • IOS 通知中心NotificationCenter

  • iOS通知中心-NSNotificationCenter

    NSNotification是iOS中一个调度消息通知的类,使用极为方便,但是劝各位还是慎用,当你日后修改工程的时...

  • iOS 通知中心(NSNotificationCenter)

    NSNotificationCenter 在这里第一步和第二步的顺序可以互换,一般楼主我喜欢先在需要发送消息的页面...

网友评论

    本文标题:iOS通知中心

    本文链接:https://www.haomeiwen.com/subject/rkvlhttx.html