选择时我能够在选择器视图中获取数据。但我的要求是当我从选择器视图中选择数据时,我希望获得标签中特定数据的ID。以下是代码:
if ([response statusCode] >= 200 && [response statusCode] < 300)
{
NSString *responseData = [NSJSONSerialization JSONObjectWithData:urlData
options:NSJSONReadingAllowFragments error:&error];
NSArray *entries = [NSJSONSerialization JSONObjectWithData:[responseData dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&error];
if(!entries)
{
NSLog(@"Error : %@", error);
}
else{
for (NSDictionary *entry in entries) {
projID = [entries valueForKey:@"ID_PROJECT"];
projectNames = [entries valueForKey:@"NM_PROJECT"];
}
NSLog(@"projID : %@", projID);
_projectpicker.delegate = self;
_projectpicker.dataSource = self;
}
} else {
}
ProjId:(1, 2, 3, 4, 五 )
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *myArrayString = [projID description];
lblProjects.text = myArrayString;
lblTasks.text = [taskNames objectAtIndex:[pickerView selectedRowInComponent:1]];
lblSubTasks.text = [subtaskNames objectAtIndex:[pickerView selectedRowInComponent:2]];
}
我的问题是我要加载lblProjects.text
中的 ProId 。
先谢谢 基兰库马尔
答案 0 :(得分:0)
只需存储entries
。作为一个数组,它为选择器提供了一个易于索引的内容列表,它包含的字典可用于填充选择器行。选择reo后,您可以使用完全相同的内容:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSDictionary *rowDict = entries[row];
lblProjects.text = rowDict[@"ID_PROJECT"];
lblTasks.text = [taskNames objectAtIndex:[pickerView selectedRowInComponent:1]];
lblSubTasks.text = [subtaskNames objectAtIndex:[pickerView selectedRowInComponent:2]];
}
目前尚不清楚选择器中显示的所有数据来自何处,但直接使用entries
数组可以解决许多潜在问题。