我試圖創建一個的NSMutableDictionary已經鑰匙由UIViewController的代表,就像這樣:設置委託類作爲主要的的NSMutableDictionary
-(void) registerAsLocationManagerDelegate:(id<RTALocationManagerDelegate>)lmDelegate forPeriodicUpdates:(NSTimeInterval)seconds
{
NSTimer* periodicTimer = [NSTimer scheduledTimerWithTimeInterval:seconds
target:self
selector:@selector(runPeriodicUpdates:)
userInfo:nil
repeats:YES];
[periodicUpdateDelegates setObject:periodicTimer forKey:lmDelegate];
}
然而,我的代碼崩潰,因爲這個錯誤:
*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: ' - [RTALocationsListViewController copyWithZone:]:無法識別的選擇發送到實例0x1a9750'
的喲方式呢?我是否通過嘗試這樣做了完全錯誤的事情?我應該採取不同的方式嗎?謝謝你的幫助!
一般來說,只要可能,您應該對關鍵對象使用「標準」類。如果你想使用你的自定義類,他們需要符合'NSCopying'協議(實現'-copyWithZone:'),你需要確保'-isEqual:'中相同的兩個對象也返回相同的值爲'-hash',並且您需要確保在對象位於字典中時,即使對象內部狀態發生更改,「-hash」也不會更改。 – 2011-06-18 11:06:10