gpt4 book ai didi

cocoa - 警告 : MyClass:NSObject does not implement key value observing? 怎么可能?

转载 作者:行者123 更新时间:2023-12-03 17:29:44 25 4
gpt4 key购买 nike

我最近刚刚恢复几个月前离开的 Cocoa 项目的工作。如果你有一段时间没有使用 cocoa ,它就是一个奇怪的野兽。

无论如何,在某个时候编译器开始丢弃警告:

Incomplete implementation of class 'MyClass'
Method definition for '-addObserver:forKeyPath:options:context' not found
Method definition for '-removeObserver:forKeyPath:' not found
Class 'MyClass' does not fully implement the 'MyZoomScrollViewDataSource' protocol

但是 MyClass 派生自 NSObject,它实际上实现了 -addObserver:forKeyPath:-removeObserver:forKeyPath:上下文:.

协议(protocol)如下所示:

@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

我想我的 cocoa 技能急需刷新。但这些方法还是应该继承自NSObject,那么MyClass怎么能不实现这些方法呢?

最佳答案

答案就在问题中!

编译器警告:

-addObserver:forKeyPath:
-removeObserver:forKeyPath:options:context:

协议(protocol):

-addObserver:forKeyPath:options:context:
-removeObserver:forKeyPath:

第二个看起来更好。

关于cocoa - 警告 : MyClass:NSObject does not implement key value observing? 怎么可能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4806445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com