解决简单的NSCSF数问题

时间:2011-04-24 06:49:54

标签: iphone objective-c

在第-[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;
        }
        }

1 个答案:

答案 0 :(得分:1)

您的pickerArray是否包含NSNumber个对象?如果是这样,要获得NSString,您需要使用+[NSString stringWithFormat:]-[NSNumber stringValue]等方法。

如果是这种情况,请尝试以下任一方法:

[firstComponentText setString:[[pickerArray objectAtIndex:row] stringValue]];

[firstComponentText setString:[NSString stringWithFormat:@"%@", [pickerArray objectAtIndex:row]]];