2011-08-11 26 views
2

我有這個managedObject子類,位置表示一個NSPoint。在XIB我想要兩個的NSTextField這樣綁定問題與NSValue包含NSPoint

http://s1.postimage.org/rkd74ebo/Schermata_08_2455785_alle_14_13_57.png

,其中一個顯示position.x值和其他顯示position.y。我試圖的NSTextField綁定到「selection.position.x」和NSArrayController的的「selection.position.y」的keyPath該管理框架

我得到這個錯誤::

[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key x.

所以我檢查KVC:

Frame.h 

@interface Frame : NSManagedObject { 

@private 

} 

@property (nonatomic, retain) NSNumber * order; 
@property (nonatomic, retain) NSNumber *visible; 
@property (nonatomic, retain) NSValue *position; 
@property (nonatomic, retain) NSNumber *scale; 
@property (nonatomic, retain) Sprite *sprite; 
@property (nonatomic, retain) Resource *resource; 

//test 
@property (nonatomic, retain) NSValue *frame; 

@end 

-(void)awakeFromInsert我試試這個代碼:

-(void)awakeFromInsert 
{ 
    [super awakeFromInsert]; 

    self.position = [NSValue valueWithPoint:NSPointFromCGPoint(CGPointZero)]; 

    //[self.position setValue:[NSNumber numberWithFloat:50.0f] forKey:@"x"]; 

    [self setValue:[NSNumber numberWithFloat:1.0f] forKeyPath:@"scale"]; 
    [self setValue:[NSNumber numberWithFloat:10.0f] forKeyPath:@"frame.origin.x"]; 
    [self setValue:[NSNumber numberWithFloat:10.0f] forKeyPath:@"position.x"]; 
} 

第一和s KVC的Econd工作的setValue,具有相同的消息,第三碰撞上述

[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key x. 

我不明白爲什麼,任何幫助是讚賞。

回答

0

NSValue對象不可變。要更改NSValue屬性,您必須創建一個新的NSValue對象,然後將其分配給該屬性。