通知(类似java中的notifyAll)多线程?
1.发布通知—>创建通知
2.接受通知
3.执行相应事件
传值时,带参数
1、发送
[[NSNotificationCenter defaultCenter]postNotificationName:@"发送红包" object:message.ext];
2、接收
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendRedPacket:) name:@"发送红包" object:nil];
3、收到通知 走方法
-(void)sendRedPacket:(NSNotification*)notification{
NSDictionary* infoDic = [notificationobject];
[selfpostDataWith:nilorder_sn:infoDic[@"order_sn"]];
}
4、移除通知
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"支付宝充值成功" object:nil];
}
传值时,不带参数
1、发送
[[NSNotificationCenter defaultCenter]postNotificationName:@"充值成功" object:nil];
2、接收
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callbackAlipay) name:@"充值成功" object:nil];
3、收到通知 走方法
-(void)callbackAlipay{
[SVProgressHUD dismiss];
[SVProgressHUD showSuccessWithStatus:@"支付成功"];
[self performSelector:@selector(popVC) withObject:nil afterDelay:1.0];
}
4、移除通知
-(void)dealloc{-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"充值成功" object:nil];
}