Search code examples
iphoneiosxcodeuipickerview

How to dectect all values of UIPickerView with 2 components in didSelectRow?


Im very new to xcode and i have a question to my first app. I have a UIPickerView with 2 components filled with NSMutableArray in my App. If the first component is changed, the second components Array got cleared and Filled with new Values. Now i have to detect the selected row in first component and the selected row in second component, to load an local HTML page in UIWebView. Ill tried it with an if loop, but i dont understand how to detect all selected rows on the 2 components. Heres a litte snippet of my sourcecode:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"the %d row was selected in the %d component", row, component);
if ((component == 0) && (row ==0)){
     [rightPickerArray removeAllObjects];
     [rightPickerArray addObject:@"5.0"];
     [rightPickerArray addObject:@"5.1"];
     [pickerView reloadAllComponents];
}
if ((component == 0) && (row ==1)){
    [rightPickerArray removeAllObjects];
    [rightPickerArray addObject:@"1"];
    [rightPickerArray addObject:@"2"];
    [pickerView reloadAllComponents];
}

if ((component ==1) && (row ==0)){
    NSString *fileString = [[NSBundle mainBundle] pathForResource:@"index" ofType: @"html"];

    NSString *newHTMLString = [[NSString alloc] initWithContentsOfFile: fileString encoding: NSASCIIStringEncoding error: NULL];

    NSURL *newURL = [[NSURL alloc] initFileURLWithPath: fileString];

    [myWebView loadHTMLString: newHTMLString baseURL: newURL];
}

Solution

  • UIPickerView has a "selectedRowInComponent:" method that's supposed to help with this. Check this out.