Ios 我希望在选择选择器视图数据时在标签中获取ID
选择时,我能够在选择器视图中获取数据。但我的要求是,当我从picker视图中选择数据时,我希望获得标签中特定数据的Id。以下是代码:Ios 我希望在选择选择器视图数据时在标签中获取ID,ios,Ios,选择时,我能够在选择器视图中获取数据。但我的要求是,当我从picker视图中选择数据时,我希望获得标签中特定数据的Id。以下是代码: if ([response statusCode] >= 200 && [response statusCode] < 300) { NSString *responseData = [NSJSONSerialization JSONObjectWithData:urlData
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 {
}
我的问题是我想在lblProjects.text
中加载ProId
提前谢谢
Kiran Kumar只需存储
条目
。作为一个数组,它为选择器提供了一个易于索引的内容列表,并且它包含的字典可用于填充选择器行。选择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]];
}
目前还不清楚选择器中显示的所有数据来自何处,但直接使用
条目
数组应该可以解决一些潜在问题。为什么不使用条目[row]
?我对这个IOS非常陌生,所以我不知道怎么做什么是项目
,任务名
,子任务
?ProjID由来自数据库(webservice)的项目ID组成,任务名和子任务在预期字段中加载数据,所有子任务都是快速响应Wain的NSArrayStank,但我在picker视图中有3个组件,其他的是项目,任务和子任务将在viewDidload方法本身中加载。那么,您还有其他建议吗?展示您如何设置选择器行(可能是pickerView:titleForRow:forComponent:
)。根据到目前为止的描述,我真的不清楚你的问题是什么。你说你有一个数组projID
,你只需要projID[row]
就可以从中提取字符串吗?-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row component:(NSInteger)component{NSNumber*myprojectarraysting=[projID objectAtIndex:row];//NSNumber*mytaskarrysting=[taskID objectAtIndex:row];//NSLog(@“%@”,myArrayString);//NSLog(@“%@”,myTaskArrayString);lblProjects.text=[NSString stringWithFormat:@“%@”,myProjectArrayString];//lblProjects.hidden=YES;lblTask.text=[taskNames objectAtIndex:[pickerView SelectedRowIncomUnit:1];//lblTask.text=[NSString stringWithFormat:@%@],myTaskArrayString];}
-(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]];
}