zoukankan      html  css  js  c++  java
  • 通知---iOS

    #import <Foundation/Foundation.h>
    #define CHILD_WEAK_NOTIFC @"childe_week"
    
    @interface Child : NSObject
    @property (nonatomic,assign) int age;
    @property (nonatomic,assign) NSInteger sleep;
    @end
    
    #import "Child.h"
    
    @implementation Child
    
    -(id) init{
        self=[super init];
        if(self!=nil){
            _sleep=100;
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeAction:) userInfo:nil repeats:YES];
        }
        return self;
    }
    
    -(void) timeAction:(NSTimer *) timer{
        _sleep-=2;
        NSLog(@"%ld",_sleep);
        if(_sleep<90){
            //发送通知
            [[NSNotificationCenter defaultCenter] postNotificationName:CHILD_WEAK_NOTIFC object:[NSNumber numberWithInteger:_sleep]];
            [timer invalidate];
        }
    }
    @end
    
    #import <Foundation/Foundation.h>
    
    @interface Father : NSObject
    
    @end
    
    #import "Father.h"
    #import "Child.h"
    
    @implementation Father
    -(id)init{
        self=[super init];
        
        if(self!=nil){
            //接收通知
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weakNotification:) name:CHILD_WEAK_NOTIFC object:nil];
        }
        return self;
    }
    -(void)weakNotification:(NSNotification *) notification{
        
         NSLog(@"sdkjflskdjf");
        NSNumber *number=notification.object;
        
        NSLog(@"%@",number);
    }
    @end
    
    Child *child=[[Child alloc]init];
            Father *father=[[Father alloc]init];
            NSLog(@"%@",child);
            [[NSRunLoop currentRunLoop] run];
    
  • 相关阅读:
    【鬼脸原创】github搭建动态网站
    WebStorm配置(2016/11/18更新)
    前端学习入门
    css笔记
    c# 将文本中的数据快速导入到数据库(200万左右的数据量)
    3.数据库单多表查询
    2.数据库表的增删改
    1.数据库建表
    浏览器的兼容性测试
    python-路径处理path
  • 原文地址:https://www.cnblogs.com/clarence/p/3920711.html
Copyright © 2011-2022 走看看