在-touchesEnded:
,添加類似下面的語句(改變handleTouchesEndedNotification
獨特的名稱要使用的通知):
[[NSNotificationCenter defaultCenter] postNotificationName:@"handleTouchesEndedNotification" object:nil userInfo:nil];
在你的主,應用程序委託或其他類,添加以下語句其中類被初始化,來監聽你在上面使用的唯一名稱的通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMyNotification:) name:@"handleTouchesEndedNotification" object:nil];
而且到你的類中,添加方法與邏輯:
- (void) handleMyNotification:(NSNotification *)notification {
// do stuff...
}
如果要將數據與通知一起傳遞,請創建一個NSDictionary
對象並將通知的userInfo
變量設置爲此字典對象。
謝謝!!!!!!你是男人! – SpaceDog 2009-09-05 11:16:10