IOS之通知NSNotificationCenter的使用
生活随笔
收集整理的這篇文章主要介紹了
IOS之通知NSNotificationCenter的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
IOS之通知NSNotificationCenter的使用
KVO是IOS的重點,必須非常熟練
通知的寫法很多,重點掌握NSNotificationCenter
在TabBarView
第一步 : 發送通知 使用post方法,創建對象是一個單例寫法,像defeat或者shared都是調用單例
在需要發送通知的類中書寫,上述,重點是幾個參數的意義,第一個是通知的名字,第二個object可以nil,第三個是傳輸給對方的參數,是一個字典類型。
來到其他類
第二步 : 注冊通知,有人叫接受通知,
此時第二個參數是重點,調用的函數,參數類型是 NSNotification ,參數名字是notification
#pragma mark - 通知 -(void)tabBarButtonDidChangeNotification:(NSNotification *)notification{ // notification.userInfoNSInteger index = [notification.userInfo[@"HMTabBarSelectIndex"] integerValue]; // NSLog(@"%zd",index);[self changeChildVc:index];}第三步 : 重寫dealloc 類銷毀的時候調用
- (void)dealloc{[[NSNotificationCenter defaultCenter]removeObserver:self]; }通知的三部曲, post創建通知, add注冊通知,dealloc銷毀通知
總結
以上是生活随笔為你收集整理的IOS之通知NSNotificationCenter的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IOS之Masonry约束的使用
- 下一篇: 瞧瞧苹果OS X如何干掉Linux