Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSMutableArray KVC/KVO问题_Objective C_Key Value Observing - Fatal编程技术网

Objective c NSMutableArray KVC/KVO问题

Objective c NSMutableArray KVC/KVO问题,objective-c,key-value-observing,Objective C,Key Value Observing,这是《MacOSX3rd(HD)Cocoa编程》一书第7章“键值编码。键值编码”中的一个示例 代码如下: 第h人: #import <Foundation/Foundation.h> @interface Person : NSObject { NSString *personName; float expectedRaise; } @property (readwrite, copy) NSString *personName; @property (

这是《MacOSX3rd(HD)Cocoa编程》一书第7章“键值编码。键值编码”中的一个示例

代码如下:

第h人:

 #import <Foundation/Foundation.h>


 @interface Person : NSObject {
    NSString *personName;
    float expectedRaise;
 }
 @property (readwrite, copy) NSString *personName;
 @property (readwrite) float expectedRaise;

 @end
MyDocument.h:

#import <Cocoa/Cocoa.h>

@interface MyDocument : NSDocument
{
    NSMutableArray *employees;
}

@property (retain) NSMutableArray *employees;

@end
而且示例工作正常。(首先是一个空白表,您可以添加或删除记录)

现在我尝试向数组中添加一些记录,这样空白表就可以了。 刚开始的时候里面有些东西

以下是我尝试过的(在init方法中):

但当我构建错误时,我得到错误消息:

[<NSConcreteData 0x422bf0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key personName.
......
[valueForUndefinedKey:]:此类不符合key personName的键值编码。
......

有人能帮我离开这里吗?提前谢谢^ ^

这似乎是一个非常合理的回答…您将NSData添加到名为
employees
的数组中;根据姓名和KVC猜测,您可能打算将
p1
添加到数组中。因此,请尝试:

[employees addObject:p1];

这似乎是一个非常合理的回答……您将NSData添加到名为
employees
的数组中;从名称和KVC中猜测,您可能打算将
p1
添加到数组中。因此,请尝试:

[employees addObject:p1];

此外,不要忘记在将p1添加到阵列后释放p1(当然,除非您仍在使用它)。此外,不要忘记在将p1添加到阵列后释放p1(当然,除非您仍在使用它)。
[<NSConcreteData 0x422bf0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key personName.
......
[employees addObject:p1];