这是我的MyManager numberOfBedrooms属性的设置方式:
@property(nonatomic, assign) NSUInteger numberOfBedrooms;
这是我从文本框中为其赋值的方法:
myManager.numberOfBedrooms = (NSUInteger) self.bedroomTextField.text;
When i enter a 1 in text box, and do the following, I get large values like 304284 WHy?
NSLog(@"bedrooms is: %@", [NSNumber numberWithUnsignedInt: myManager.numberOfBedrooms] );
NSLog(@"bedrooms is: %d", myManager.numberOfBedrooms );
答案 0 :(得分:3)
更改为:
myManager.numberOfBedrooms = (NSUInteger) [self.bedroomTextField.text intValue];
答案 1 :(得分:0)
你不能做这个转换(你将一个对象转换为一个int):
myManager.numberOfBedrooms = (NSUInteger) self.bedroomTextField.text;
您应该执行以下操作:
myManager.numberOfBedrooms = [self.bedroomTextField.text intValue];