0

有一个自定义属性:

@property (nonatomic, readwrite) SIListVCDisplayType displayType;

当我提到它时,它必须是 via displayType,而不是_displayType。为什么?我认为实例变量需要_在他们的名字之前有?

例如,如果我写:

@property (nonatomic, strong) NSArray *test;

然后它工作....

4

2 回答 2

1

I would say in any case you should use self.displayType IF you use @synthesize. If not (as it would seem from the title) you should ALWAYS create your own SIListVCDisplayType in your class and name it as you please.

If you create a property called NAME, you will seem to get a _NAME parameter in class as well in most cases. This is because of how objective C works, not how you should use it. Create your own and bind it to. I see no reason at all that this type of naming and creating variables behind the scene will stay the same, so unless you find some documentation saying otherwise it might happen your code will not even compile after some update.

于 2013-04-17T09:58:59.170 回答
0

您确定可以使用它访问属性ivardisplayType吗?我试图重现您的问题,并且我使用了带有枚举类型的@property ,但我无法使用UAProducStatus它来访问它displayType,但我可以使用_displayType.

我能猜到的是你要么定义了局部变量或同名的 ivar,要么你有 @synthesize displayType = displayType;

于 2013-04-17T10:10:36.563 回答