zoukankan      html  css  js  c++  java
  • 通知PostNotification

    //
    //  ViewController.m
    //  FKLTest
    //
    //  Created by kun on 16/8/10.
    //  Copyright © 2016年 kun. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "FKLTool.h"
    #import "XMGDownloadTool.h"
    #import "PostNotificationViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        NSLog(@"******#receiveNotification--Begin#******");
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification) name:@"postNotification" object:nil];
        NSLog(@"******#receiveNotification--End#******");
    
    }
    
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        PostNotificationViewController *postVc = [[PostNotificationViewController alloc] init];
        
        [self presentViewController:postVc animated:YES completion:nil];
    }
    
    - (void)receiveNotification
    {
        NSLog(@"---begin---%s", __func__);
        sleep(5.0);
        NSLog(@"---after---%s", __func__);
    }
    
    @end
    //
    //  PostNotificationViewController.m
    //  FKLTest
    //
    //  Created by kun on 16/8/24.
    //  Copyright © 2016年 kun. All rights reserved.
    //
    
    #import "PostNotificationViewController.h"
    
    @interface PostNotificationViewController ()
    
    @end
    
    @implementation PostNotificationViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSLog(@"******#postNotification--Begin#******");
        [[NSNotificationCenter defaultCenter] postNotificationName:@"postNotification" object:nil];
        NSLog(@"******#postNotification--End#******");
    }
    
    @end
    2016-08-24 18:54:07.713 FKLTest[1186:24510] ******#receiveNotification--Begin#******
    2016-08-24 18:54:07.714 FKLTest[1186:24510] ******#receiveNotification--End#******
    2016-08-24 18:56:15.805 FKLTest[1186:24510] ******#postNotification--Begin#******
    2016-08-24 18:56:15.806 FKLTest[1186:24510] ---begin----[ViewController receiveNotification]
    2016-08-24 18:56:20.807 FKLTest[1186:24510] ---after----[ViewController receiveNotification]
    2016-08-24 18:56:20.808 FKLTest[1186:24510] ******#postNotification--End#******

    分析:监听通知必须要在发送通知之前设置好。发送通知,如果有监听此通知的观察者,会等待观察者的监听方法处理完后才会返回;如果没有则立马返回。

  • 相关阅读:
    Visual C# 2008+SQL Server 2005 数据库与网络开发14.1.2 WPF的组成
    Visual C# 2008+SQL Server 2005 数据库与网络开发13.1.3 简单记事本程序菜单设计
    Visual C# 2008+SQL Server 2005 数据库与网络开发13.1.1 菜单创建
    Feathers TextInput使KeyboardEvent失效
    UILabel 多行显示
    突破flash player的睡眠模式
    突破flash player睡眠模式 后续
    缩放UIImage
    IT菜鸟报到!
    用VMware装了Ubuntu后,安装VMware Tools
  • 原文地址:https://www.cnblogs.com/fkunlam/p/5804277.html
Copyright © 2011-2022 走看看