gpt4 book ai didi

iphone - 依赖 UIPickerView

转载 作者:行者123 更新时间:2023-12-03 19:10:49 27 4
gpt4 key购买 nike

有谁知道如何制作依赖的 UIPickerView.例如,当我选择组件一的第 2 行时,组件二的标题会发生变化吗?

我在互联网上查找过,没有真正的答案,我尝试过使用 if 和 switch 语句,但它们只是崩溃了。

最佳答案

这取决于您将如何保存数据。例如,如果您有一个数组作为字典键的值,并且该字典具有不同的此类键,则第一列将是键,选择一个数组后,您将在另一列(组件)。 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 方法应返回 2。在 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component方法中,您需要给出组件 1 的字典中键的数量,以及当前所选键的数组的数量。例如

if(component==0) return [[DICTIONARY allKeys] count];
else return [[DICTIONARY objectForKey:@"SELECTED_KEY"] count];

那么,

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

selectedIndex = [pickerView selectedRowInComponent:0];
if (component == 1 && !(selectedIndex < 0)) {
[pickerView reloadComponent:2];

[pickerView selectRow:0 inComponent:2 animated:YES];
}

}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

UILabel *pickerRow = (view != nil) ? view : [[[UILabel alloc] initWithFrame:CGRectMake(5, 0, 115, 60)] autorelease];
pickerRow.font = [UIFont boldSystemFontOfSize:14];
pickerRow.textAlignment = UITextAlignmentLeft;
pickerRow.backgroundColor = [UIColor clearColor];
pickerRow.textColor = [UIColor blackColor];
pickerRow.numberOfLines = 0;
if (component == 0) {

pickerRow.text = @"DICTIONARY_ROW'th_KEY";
}
else {

pickerRow.text = [[dictionary objectForKey:@"SELECTED_KEY"] objectAtIndex:row];

}
return pickerRow;
}

关于iphone - 依赖 UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5311552/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com