iOS註冊系統通知

iOS編程裏面,用到系統通知來接受事件是十分普遍的,最典型的就是鍵盤的通知事件。我們也可以自己定義通知的事件,讓系統來調去我們想要的函數。


 // 註冊通知

        [[NSNotificationCenter defaultCenter] addObserver:self 

                                                 selector:@selector(responseNotification:) 

                                                     name:DIQUN 

                                                   object:nil];

        

        [[NSNotificationCenter defaultCenter] addObserver:self 

                                                 selector:@selector(acceptNotification:) 

                                                     name:DIQUN

                                                   object:nil];


 // 實現通知的函數

- (void)responseNotification:(NSNotification *)notification

{

    A *render = (A *)notification.object;

}


 //發送通知
A *render ;

[[NSNotificationCenter defaultCenter] postNotificationName:DIQUN object:render];


這樣就可以通過通知的形式,來調取我們需要的函數,來實現無對象引用的混合編程。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章