iOS 通知的使用,以及場景(未確定版本)
阿新 • • 發佈:2019-02-05
首先我們要再處理事件的視圖裡面建立通知(比如。視圖裡面的按鈕被點選了,但是這個事件不能在視圖裡面解決,就需要用通知)
一、首先
//建立通知
NSNotification *notification =[NSNotificationnotificationWithName:@"tongzhi"object:nil];
//通過通知中心傳送通知
[[NSNotificationCenterdefaultCenter] postNotification:notification];
(建立場景。 一般在按鈕點選事件裡面寫)
一、其次
以下的步驟一般都要寫在控制器裡面
在ViewDidLoad 中 註冊通知在selector方法裡面寫一個想要呼叫的方法, 一般可隨機定義
- (void)viewDidLoad {
[superviewDidLoad];
//註冊通知
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(shouldBtnOnClick) name:@"tongzhi"object:nil];
}#pragma mark - 通知的實現方法
- (void)shouldBtnOnClick
{
[MessageView showAlertMoney:
NSLog(@"111111");
} cancelTitle:@"取消"cancelOption:^{
NSLog(@"2222222");
} inView:self.view];
}