我有一个定义为int类的属性。我检索int值(它是15),并将其分配给UISlider.value,并且它始终显示为max,即使max设置为100 - 这是因为分配/检索的值比它应该大得多。我敢肯定,这对我而言是一个简单的误解,即对象c和c在一般情况下是如何工作的。Objective-C:我的int值不是我期望的值
这里是我的代码:
// device is retrieved from my app delegate NSMutableArray
uiSlider.value = device.nodeLevel;
如果我把一个断点在该行并拉起GDB,当我执行这个命令:
po [device nodeLevel]
它打印出“15”,这是因为这是int属性设置较早的时间。
然而,当我这样做:
print [device nodeLevel]
我最终的实际值被分配到滑块的value属性......这是“100812800” - 这似乎像这是一个内存地址或一些东西。无论如何,这是而不是我分配给nodeLevel的值,因此不是我想要分配给我的滑块的value属性的值。
我错过了什么?
仅供参考,这里是我的设备类的声明:
// Device.H file
@interface Device : NSObject {
@private int nodeLevel;
}
@property (readwrite, assign, nonatomic) int nodeLevel;
// Device.m file
@implementation Device
@synthesize nodeLevel;
- (id)init {
self.nodeLevel = 0;
return self;
}
如何分配给nodeLevel?你得到什么编译器警告? – 2010-11-05 15:50:47