ya i am using pickerview but i dont want to display array of objects simply.instead i want that if i select an object in 1st picker so it should dynamically change and display its corresponding objects in 2nd picker below it.. plz help.. i am stuck with it from 2days.... thanks
A:
It's kind of easy. Have a look at this implementation. Maybe this helps, if not, feel free to ask.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0)
return 2;
return 5;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0) {
if (row == 0)
return @"A";
if (row == 1)
return @"B";
}
if (component == 1)
return [pickerArray objectAtIndex:row];
return @"FOO";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (component == 0) {
if (row == 0) {
[pickerArray release];
pickerArray = [[NSArray arrayWithObjects:@"Aa", @"Ab", @"Ac", @"Ad", @"Ae", nil] retain];
}
if (row == 1) {
[pickerArray release];
pickerArray = [[NSArray arrayWithObjects:@"Ba", @"Bb", @"Bc", @"Bd", @"Be", nil] retain];
}
}
[pickerView reloadComponent:1];
}
fluchtpunkt
2010-10-13 10:41:10
hey thanks..its working fine..now if i select like say A and Ab or any other combination some action should be performed.
rose
2010-10-14 08:55:37
Like for A and Ab i have 3 textfields with 3 labels.For B and Bc i have 6 textfields with 6 labels.This should be dynamic.how would i do that??
rose
2010-10-14 08:55:59
Put some code in pickerView:didSelectRow:inComponent: that adds (and removes) those UIViews if component 1 changed. [self.view addSubview:label] etc.
fluchtpunkt
2010-10-14 10:32:41