码迷,mamicode.com
首页 > 移动开发 > 详细

通知---iOS

时间:2014-08-19 00:47:13      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   ar   cti   div   log   ad   

#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];

 

通知---iOS,布布扣,bubuko.com

通知---iOS

标签:blog   os   io   ar   cti   div   log   ad   

原文地址:http://www.cnblogs.com/clarence/p/3920711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!