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;
}
[[NSNotificationCenter defaultCenter] postNotificationName:DIQUN object:render];
這樣就可以通過通知的形式,來調取我們需要的函數,來實現無對象引用的混合編程。