谁知道如何将web服务中的类别列表填充到UIPickerView中?另外,是否有可能放入一个隐藏值?
例如,
隐藏id为“%1”的"Public“
隐藏id为"2“的"Member”,依此类推。
这两个值来自the服务。顺便说一句,我正在使用ASIHTTPRequest框架。
我是iOS/XCode/Objective C的新手。希望有人能帮上忙):谢谢
===============响应================
@MSgambel
好的,我尽量解释一下。目前,我们如何将项目放入UIPickerView中:
NSArray arrayWithObjects:@"John Appleseed",@"Chris Armstrong",@"Serena Auroux",@“苏珊·宾”,@"Luis Becerra",@“凯特·贝尔”,@"Alain Briere",nil;
除了上面的那些项目,我该如何将the服务中的项目填充到选择器中?
@Akshay
我所说的隐藏是指选取器将有2个值,但在选取器上只有标签"Public“可见,而id "1”则不可见。我想实现它有点类似于网站上的下拉菜单。
在名为"Domain“的数据库中,我们具有以下格式的值:
DomainID : DomainName
1:公共
2: CompanyA
3: CompanyB
将会有另一个数据库“用户”,在那里它被绑定到DomainID。(仅举个例子)
选取器将在界面上显示"Public“,当用户选择它时,它的值将为"1”。那么有没有什么办法可以让我做这样的事情呢?
发布于 2011-08-11 13:29:48
首先,您没有提供有关您的web服务细节的详细信息。假设它是基于SOAP的,那么我强烈推荐使用sudzc或wsd2lobjc。这些将为您生成代码,以便很好地将您的WSDL def转换为Objective C类。
至于UIPickerView“隐藏”值的问题,这个问题非常简单。创建NSDictionaries的NSArray。使用您的示例(假设所有都是字符串):
NSDictionary *dictOne = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"realValue",@"Public",@"looksGoodValue",nil]; NSDictionary *dictTwo = [NSDictionary dictionaryWithObjectsAndKeys:@"2",@"realValue",@"CompanyA",@"looksGoodValue",nil]; NSDictionary *dictTre = [NSDictionary dictionaryWithObjectsAndKeys:@"3",@"realValue",@"CompanyB",@"looksGoodValue",nil];
array = [NSArray arrayWithObjects:dict1,dict2,dict3,nil];
在您的UIPickerViewDelegate方法中
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [[self.array objectAtIndex:row] objectForKey:@"looksGoodValue"];
}
最后,在您使用选择器视图的任何地方(比如您的web服务)
request.realValue = [[self.array objectAtIndex:[pickerView selectedRowInComponent:0]] valueForKey:@"realValue"];
希望这能有所帮助!
发布于 2011-08-11 13:38:34
在您使用ASIHTTPRequest加载这些值之后,我会将它们保存在propertyList中。要保存文件,请使用
**` `NSArray *路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
** NSString *documentsDirectory =路径对象属性索引:0;
* NSString *path = documentsDirectory stringByAppendingPathComponent:@"data.plist";
* NSMutableArray *array = [NSMutableArray alloc init];* addObject:[NSArray arrayWithObjects:NSString stringWithFormat:@"%@",stringOne,//像这样添加所有字符串]];*数组写入that :path alloc:YES;`
然后使用[NSMutableArray alloc] initWithContentsOfFile:path]将值加载到pickerView中。
https://stackoverflow.com/questions/7020374
复制相似问题