gpt4 book ai didi

iphone - 如何根据另一个选择器的选择更改选择器行?

转载 作者:行者123 更新时间:2023-12-04 06:00:49 28 4
gpt4 key购买 nike

我有两个选择器——国家和地区。我需要根据在国家选择器中选择的行来填充区域选择器。我有数组来填充两个选择器。我需要一些帮助来根据国家选择器的选择更改区域选择器的行。任何帮助将不胜感激。提前非常感谢。

最佳答案

好的,你有两个选择器,比如说 countryPicker 和 regionPicker。

在 UIPickerView 的委托(delegate)方法中添加一个条件

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *pickerTitle = @"";
if (pickerView == countryPicker)
{
pickerTitle = [countryFeeds objectAtindex:row];
//assigns the country title if pickerView is countryPicker
}
else if (pickerView == regionPicker)
{
pickerTitle = [regionFeeds objectAtindex:row];
//assigns the region title if pickerView is regionPicker
}

return pickerTitle;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView == countryPicker)
{
//selects the region corresponding to the selected country.
//totalRegions is a NSDictionary having country names as keys and array of their regions as values
regionFeeds = [totalRegions objectForKey:[countryFeeds objectAtindex:row]];

//Now reloading the regionPicker with new values.
[regionPicker reloadAllComponents];
}
else if (pickerView == regionPicker)
{
// your code to select a region
}
}

我希望这能解决你的问题:)
BR,哈里

关于iphone - 如何根据另一个选择器的选择更改选择器行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8924886/

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