gpt4 book ai didi

ios - DownPicker选中时如何获取Array Index Value

转载 作者:行者123 更新时间:2023-11-28 23:59:46 25 4
gpt4 key购买 nike

我已经关注了这个link安装DownPicker。选择项目时,我需要获取 NSMutableArray 索引值。背后的原因是我有 2 个数组。一种用于国家/地区,一种用于代码。当用户选择国家时,我需要获取索引值才能获取代码。非常感谢任何帮助。

- (void)viewDidLoad
{
[super viewDidLoad];

//=== Initiallize the Mutable Array
countryMArray = [[NSMutableArray alloc] init];
codeMArray = [[NSMutableArray alloc] init];

//=== Initialize the responseData Mutable Data
self.responseData = [NSMutableData data];

//=== Pass the string to web and get the return Country response.write
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
sURL = appDelegate.gURL;
sURL = [sURL stringByAppendingString:@"/apps/getcountry.asp?"];

NSURLRequest *requestCountry = [NSURLRequest requestWithURL:[NSURL URLWithString:sURL]];

(void) [[NSURLConnection alloc] initWithRequest:requestCountry delegate:self];

//=== Pass the string to web and get the return Code response.write
sURL = appDelegate.gURL;
sURL = [sURL stringByAppendingString:@"/apps/getctcode.asp?"];

NSURLRequest *requestCode = [NSURLRequest requestWithURL:[NSURL URLWithString:sURL]];

(void) [[NSURLConnection alloc] initWithRequest:requestCode delegate:self];

self.pickerCountry = [[DownPicker alloc] initWithTextField:self.txtCountry withData:countryMArray];

最佳答案

viewDidLoad中添加一个目标到pickerCountry

 [self.pickerCountry addTarget:self 
action:@selector(pickerClicked:)
forControlEvents:UIControlEventValueChanged];

//

-(void)pickerClicked:(id)dp {

NSString* selectedValue = [self.pickerCountry text];

for ( int i = 0 ; i < countryMArray.count; i++) {

NSString*item = [countryMArray objectAtIndex:i];

if([item isEqualToString:selectedValue])
{
[self.pickerCode selectRow:i inComponent:0 animated:YES];

break;
}

}
}

关于ios - DownPicker选中时如何获取Array Index Value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49897541/

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