通知的思路要清楚:创建通知==>发送通知==>注册通知==>接受通知调用那个函数
第一步:
//创建通知
//接收到通知后要传的参数
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:sender.titleLabel.text,@"oneName",[NSString stringWithFormat:@"%ld",(long int)sender.tag],@"oneId",nil];
//创建通知对象
NSNotification *notification = [NSNotification notificationWithName:@"shopChangeData" object:nil userInfo:dict];
//通过通知中心发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
第二步:在你要接受通知的控制器里注册通知的监听
//监听数据的通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(noticeData:) name:@"shopChangeData" object:nil];
//触发的函数
//接受Data发过来的通知
-(void)noticeData:(NSNotification *)text
{
//更新数据
NSLog(@"%@",text.userInfo[@"oneName"]);
NSLog(@"%@",text.userInfo[@"oneId"]);
NSLog(@"数据==>HOME");
[self initWithNav:text.userInfo[@"oneName"]];
}
注:如果第二步通知没有注册是不会接受到通知的,通知会丢弃。