开发者

Binding problem with a NSValue that contains NSPoint

I have this managedObject subclass, position rappresent a NSPoint. In a XIB I want two NSTextField like this

Binding problem with a NSValue that contains NSPoint

where one display position.x value and the other display position.y. I tried to bind the NSTextField to a "selection.position.x" and "selection.position.y" keyPath of a NSArrayController that manage Frames

I get this error::

[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the k开发者_如何学Goey x.

So i checked 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

In -(void)awakeFromInsert I try this code:

-(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"];
}

The first and second KVC setValue works, the third crash with the same message above

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

I don't understand why, any help is appreciate.


NSValue objects are not mutable. To change a NSValue property, you have to create a new NSValue object and then assign it to the property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜