首先我们要再处理事件的视图里面创建通知(比如。视图里面的按钮被点击了,但是这个事件不能在视图里面解决,就需要用通知)
一、首先
//创建通知
NSNotification *notification =[NSNotification notificationWithName:@"tongzhi" object:nil];
//通过通知中心发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
(创建场景。 一般在按钮点击事件里面写)
一、其次
以下的步骤一般都要写在控制器里面
在ViewDidLoad 中 注册通知在selector方法里面写一个想要调用的方法, 一般可随机定义
- (void)viewDidLoad {
[super viewDidLoad];
//注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shouldBtnOnClick) name:@"tongzhi" object:nil];
}
#pragma mark - 通知的实现方法
- (void)shouldBtnOnClick
{
[MessageView showAlertMoney:@"200" SureTitle:@"确定" sureOption:^{
NSLog(@"111111");
} cancelTitle:@"取消" cancelOption:^{
NSLog(@"2222222");
} inView:self.view];
}