我創建了一個自定義的類的對象操作有三個枚舉實例變量:無法識別的選擇發送到實例上的自定義對象
@interface Action : NSObject <NSCopying>
@property ImageSide imageSide; //typedef enum
@property EyeSide eyeSide; //typedef enum
@property PointType pointType; //typedef enum
@property int actionId;
- (id) initWithType:(int)num eyeSide:(EyeSide)eyes type:(PointType)type imageSide:(ImageSide)image;
@end
使用這種實現:
@implementation Action
@synthesize imageSide;
@synthesize eyeSide;
@synthesize pointType;
@synthesize actionId;
- (id) initWithType:(int)num eyeSide:(EyeSide)eyes type:(PointType)type imageSide:(ImageSide)image {
// Call superclass's initializer
self = [super init];
if(!self) return nil;
actionId = num;
imageSide = image;
eyeSide = eyes;
pointType = type;
return self;
}
@end
而在我的ViewController,我嘗試將它作爲一個鍵添加到NSMutableDictionary對象,如下所示:
Action* currentAction = [[Action alloc] initWithType:0 eyeSide:right type:eye imageSide:top];
pointsDict = [[NSMutableDictionary alloc] initWithCapacity:20];
[pointsDict setObject:[NSValue valueWithCGPoint:CGPointMake(touchCoordinates.x, touchCoordinates.y)] forKey:currentAction];
但是,我得到t他的錯誤,當的setObject叫做:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Action copyWithZone:]: unrecognized selector sent to instance
我通過SO與這個錯誤一些答案去了,但似乎沒有人來解決這個問題,並作爲我新的iOS開發我的挺納悶這個。
確實。非常感謝。 – MobileCushion