这是设置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 );

最佳答案

改成:

 myManager.numberOfBedrooms = (NSUInteger) [self.bedroomTextField.text intValue];

10-08 15:43