I am very new o XCode. I was using Picker VIew and got stuck at one place.
I have a Picker View with two Components. And I have three arrays. Array, Array1, Array2.
Now what I want to accomplish is that. When the first object of Array is selected in Component 0, second component gets populated by Array 1.
And when second object is selected from Array in first component. Second Component gets reloaded and gets populated by Array2.
I am very confused on how to accomplish this.
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [Array count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (component == 0)
return [Array objectAtIndex:row];
else
return [[ArraysOFArrays objectAtIndex:row]objectAtIndex:0 ];
//ArraysOFArrays = Array1 & Array2
[technologyPicker reloadComponent:1];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
if ((component == 0) && (row ==0))
{
if (component == 1)
{
[Array1 objectAtIndex:0];
}
selectTechnology.text = [technologyData objectAtIndex:row];
[technologyPicker reloadComponent:1];
}
if ((component == 0) && (row ==1))
{
if (component == 1)
{
[Array2 objectAtIndex:0];
}
[technologyPicker reloadComponent:1];
}
}
I have modified your code try this. Take a global variable “selected” of type int and initialize its value to 0 . And BTW what is this “technologyData”?
No of components
No of Rows in component
title for row
did Select row in a component