i am getting the following error when I load the view with my UIPickerView:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x5906000’
Here is all my code related to the picker:
-(void)viewDidLoad:
NSMutableArray * array = [[NSMutableArray alloc] initWithCapacity:700];
for ( int i = 1 ; i <= 100 ; i ++ )
[array addObject:[NSNumber numberWithInt:i]];
weightArray = array;
//[array release];
#pragma mark - Weight Picker
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
return [weightArray count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [weightArray objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// NSLog(@"Selected Color: %@. Index of selected color: %i", [weightArray objectAtIndex:row], row);
}
Update
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
if (thePickerView.tag==1)
{
//float weight = [[pickerArray objectAtIndex:row] intValue];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
float weight = [[pickerArray objectAtIndex:row] floatValue];
label.text = [NSString stringWithFormat:@"%f lb", weight];
//label.text = [NSString stringWithFormat:@"%f lb", weight];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:30];
[label autorelease];
return label;
}
else
{
int reps = [[pickerArray objectAtIndex:row] intValue];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
label.text = [NSString stringWithFormat:@"%d reps", reps];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:30];
[label autorelease];
return label;
}
}
Faisal,
I think problem lies
in above method… weightArray is array of NSNumber. and you are treating it as string you should rather try following
Regarding Picker methods
Thanks,