我最近剛剛恢復了幾個月前離開的Cocoa項目的工作。可可是一個奇怪的野獸,如果你沒有使用它一段時間。警告:MyClass:NSObject沒有實現鍵值觀察?怎麼可能?
無論如何,在某些時候,編譯器開始下降警告:
完全執行類「MyClass的」
方法定義爲「-addObserver:forKeyPath:選擇:上下文」未找到
的 方法定義'-removeObserver:forKeyPath:' 未找到
類 'MyClass的' 不全面貫徹 'MyZoomScrollViewDataSource' 協議
但MyClass
源自NSObject
,其實際上實施-addObserver:forKeyPath:
和-removeObserver:forKeyPath:context:
。
協議看起來是這樣的:
@protocol MyZoomScrollViewDataSource
// The range of Data that should be shown. This corresponds to the horizontal
// zoom and the scroll value of self.
@property FRange selectionRange;
// Also, make sure the dataSource is KVO compliant
- (void)addObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context;
- (void)removeObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath;
@end
類看起來是這樣的:
@interface MyClass : NSObject <MyZoomScrollViewDataSource> {
IBOutlet Outlets...
variables...
}
@properties...
(IBAction)actions...
- methods...
@end
我想我的可可技能是深需要刷新。但是,這些方法仍然應該從NSObject
繼承,那麼MyClass
不能實現這些方法?
「MyClass」與「NovaController」相同嗎? – 2011-01-27 08:36:13
@Bavarious:是的。我相應地糾正了這個問題。 – bastibe 2011-01-27 08:48:20