iOS通知(Notification)

作者: Paco_Ke | 来源:发表于2016-08-09 09:50 被阅读152次
- (IBAction)buttonClick:(id)sender {
    //添加 字典,将label的值通过key值设置传递
    NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:self.textFieldOne.text,@"textOne",self.textFieldTwo.text,@"textTwo",nil];
    //创建通知
    NSNotification *notification =[NSNotification notificationWithName:@"tongzhi" object:niluserInfo:dict];
    //通过通知中心发送通知
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    [self.navigationController popViewControllerAnimated:YES];
 
}
在发送通知后,在所要接收的控制器中注册通知监听者,将通知发送的信息接收

- (void)viewDidLoad {
    [super viewDidLoad];
    //注册通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:)name:@"tongzhi" object:nil];
 
}
- (void)tongzhi:(NSNotification *)text{
    NSLog(@"%@",text.userInfo[@"textOne"]);
        NSLog(@"-----接收到通知------");
 
}

移除通知:removeObserver:和removeObserver:name:object:

相关文章

  • iOS适配

    1.iOS10的适配 (1).Notification(通知) 自从Notification被引入之后,苹果就不断...

  • 通知及Block传值代码示例

    通知 在IOS中,主要有广播通知(broadcast notification)、本地通知(local notif...

  • iOS 通知Notification

    // ViewController.m // 通知的使用 // // Created by yunhuihuang...

  • iOS通知(Notification)

  • iOS通知Notification

    通知模式:⼀一个对象能够给其他任意数量的对象⼲⼴广播信息。对象之 间可以没有耦合关系。 NSNotificatio...

  • iOS Notification(通知)

    通知机制想必大家都很熟悉,平常的开发中或多或少的应该都用过。它是 Cocoa 中一个非常重要的机制,能把一个事件发...

  • iOS 通知机制总结

    iOS中提供了2种推送通知 本地推送通知(Local Notification) 远程推送通知(Remote No...

  • iOS-消息推送

    iOS 消息推送包括远程推送通知(Remote Notification)和本地推送通知(Local Notifi...

  • 26 - 推送

    iOS中提供了2种推送通知: 本地推送通知(Local Notification) 远程推送通知(Remote N...

  • iOS 远程通知

    iOS推送通知分为两种: 远程推送通知(Remote Notification) 苹果的远程通知服务 APNs(A...

网友评论

  • 蕾蕾是女神:写具体一点呗。加个例子,或者上个demo都好。
    Paco_Ke:@蕾蕾是女神 感谢提出意见,晚上会补全具体

本文标题:iOS通知(Notification)

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