0

我使用以下头文件和带有@synthesize 的正文文件创建了一个名为“card”的类。问题是当我尝试获取 typeOfCard 的值时应用程序崩溃。我傻吗?当我调试它时,检查器告诉我这个变量是一个 int 并且它告诉我正确的值,但随后应用程序崩溃并出现以下错误:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSArrayM idOfImage]:无法识别的选择器发送到实例 0x190f64e0”

#import <Foundation/Foundation.h>

enum cardType {
    hearth = 0,
    bell = 1,
    acorn = 2,
    leaf = 3
    };

@interface card : NSObject {
    int value;
    int idOfImage;
    enum cardType typeOfCard;
}

@property (assign)int value;
@property (assign)int idOfImage;
@property enum cardType typeOfCard;

@end
4

2 回答 2

0

错误消息是正确的。我失败了一点,我尝试做 NSARRAY.idOfCard 而不是我的卡片课程。

于 2012-11-23T16:44:05.310 回答
0

try changing the following:

1) declare your enum like (tip: use capital letters for enumerators, same as with classes)

typedef enum {
    hearth = 0,
    bell = 1,
    acorn = 2,
    leaf = 3
} CardType;

2) correct your @property line

@property (assign) CardType typeOfCard;

3) make sure you have the @synthesize typeOfCard; in your .m

于 2012-11-23T16:45:48.790 回答