【问题标题】:How to dectect all values of UIPickerView with 2 components in didSelectRow?如何在 didSelectRow 中使用 2 个组件检测 UIPickerView 的所有值?
【发布时间】:2012-09-02 22:34:08
【问题描述】:

我对 xcode 非常陌生,我对我的第一个应用程序有疑问。 我的应用程序中有一个 UIPickerView,其中包含 2 个组件,其中填充了 NSMutableArray。如果第一个组件发生更改,则第二个组件数组将被清除并填充新值。 现在我必须检测第一个组件中的选定行和第二个组件中的选定行,以在 UIWebView 中加载本地 HTML 页面。 我会用 if 循环尝试它,但我不明白如何检测 2 个组件上的所有选定行。 这是我的源代码的一个小sn-p:

- (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];
}

【问题讨论】:

    标签: iphone ios xcode uipickerview


    【解决方案1】:

    UIPickerView 有一个“selectedRowInComponent:”方法可以帮助解决这个问题。签出this

    【讨论】:

    • 我很抱歉,但问题是,我无法将其转换为 if 循环。我希望你能帮助我并给我更多的信息。
    • int newRow = [pickerView selectedRowInComponent:1]; if(newRow == 2) { //do something } 不知道你说的不能翻译成“if loop”是什么意思
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多