在第-[NSCFNumber length]: unrecognized selector sent to instance
行获取错误:[firstComponentText setString:[pickerArray objectAtIndex:row]];
。
-(void) viewDidLoad
pickerArray = [[NSMutableArray alloc] initWithCapacity:700];
for ( float i = 0.0 ; i <= 1000.0 ; i = i + 2.5)
[pickerArray addObject:[NSNumber numberWithFloat:i]];
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (thePickerView.tag==1)//weight
{
[firstComponentText setString:[pickerArray objectAtIndex:row]];
weightLabel.text = firstComponentText;
}
}
答案 0 :(得分:1)
您的pickerArray
是否包含NSNumber
个对象?如果是这样,要获得NSString
,您需要使用+[NSString stringWithFormat:]
或-[NSNumber stringValue]
等方法。
如果是这种情况,请尝试以下任一方法:
[firstComponentText setString:[[pickerArray objectAtIndex:row] stringValue]];
或
[firstComponentText setString:[NSString stringWithFormat:@"%@", [pickerArray objectAtIndex:row]]];