Sportica   Sportica

iOS NSNotificationCenter 最基本使用

 

 

 

 NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:2] , @"actcode",nil];
    //首先设置需要通知的方法。加入通知中心。比如当程序跑到这时就通知游戏
    [[NSNotificationCenter defaultCenter] postNotificationName:gameStartNotification object:nil userInfo:dic];



//调用时--------------------------------------------

//注册消息通知  捕获游戏start时的方法
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(testNotify:) name:gameStartNotification object:nil];


//实现方法
-(void)testNotify:(NSNotification*)notify
{
    NSLog(@"testNotify:%@",notify);
}

 

posted @ 2014-06-11 16:37  qingjoin  阅读(2310)  评论(0编辑  收藏  举报
  Sportica