I have a pickerview with 2 columns, populated with numbers for angle and velocity. I eventually get their intValues so I can do a simple calculation. However whenever I select say component 3 on the second column NSlog also prints me the value for component 3 on the first column regardless of what component is selected.
Code:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *angle =[list objectAtIndex:row];
NSString *velocity = [velList objectAtIndex:row];
//the angle and velocity had to be parsed to get rid of the ".kts" after the number etc..
NSString *realAngle = [angle substringWithRange:NSMakeRange(0,2)];
NSString *realVelocity = [velocity substringWithRange:NSMakeRange(0,2)];
double intVel = [realVelocity intValue];
double intAngle = [realAngle intValue];
float radAngle = (intAngle * M_PI/180);
float degAngle = sin(radAngle);
if (component == 0)
{
NSLog(@"%f",intVel);
NSLog(@"%f", degAngle);
}
else
{
NSLog(@"%f",intVel);
NSLog(@"%f", degAngle);
}
}
Last edited by starvingpilotcompany; 02-08-2012 at 10:44 AM.
Look at where/how you are using "component" in that code. Why would you expect the output to be any different?
To tell you truth, I had a feeling it was that part of the code. I just started writing obj. c so I am not too familiar with this method. How can I differentiate the output so I can have "row/component" and something else?
I can't say, because I don't know how your data is arranged. I will guess that if you are getting the data into the correct components in the first place, then that would be your clue.
I can't say, because I don't know how your data is arranged. I will guess that if you are getting the data into the correct components in the first place, then that would be your clue.
Everything is working, in fact NSLog will log the proper info. In angles I have 10, 20, 30 and in the velocity, I have 1, 2, 3. When I select the angle of 20, it will Log, 20 and the velocity of 2 and if I leave the angle on 20 when I select 3 on the right side, it will log whatever 30 even though the 20 is selected.
This method is telling you what was touched. So it was row 5 in the second column, or whatever. It doesn't tell you anything about any other columns or rows. So if you need that information, you will have to interrogate the picker.
This method is telling you what was touched. So it was row 5 in the second column, or whatever. It doesn't tell you anything about any other columns or rows. So if you need that information, you will have to interrogate the picker.
Gotcha, I will read a little more and figure out which method I need. Thanks for clearing that up.