您的位置:首页 > 移动开发 > IOS开发

ios-通知

2014-04-15 15:27 190 查看
//先写写心得,通知中心是一个单例,要用通知的时候可以先建立一个通知,然后发送给通知中心,如果通知中心有监听这个通知的话,立马就会做出响应。通知常用于不同类之间传递数据。。晚上回去写代码


NSMutableDictionary*aa=[[NSMutableDictionary alloc]init];
[aa setObject:@"liyang" forKey:@"key"];
NSNotification*nsnotification= [[NSNotification alloc]initWithName:@"mynotification" object:@"nono" userInfo:aa];
[[NSNotificationCenter defaultCenter] postNotification:nsnotification];//通知中心发送一个通知
[[NSNotificationCenter defaultCenter]postNotificationName:@"mysecode" object:@"ddd" userInfo:aa];//这是第二种方法发送通知


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rrrr:) name:@"mysecode" object:nil];//这是通知中心舰艇了这个通知
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: