1
我有一个uipickerview用于在uitextfield中显示名称,以及关于如何将隐藏于用户的值传递给变量的任何想法。我可以以某种方式将值与NSArray中的名称关联,但不显示它。 谢谢UIPickerView数据
尝试一个字典,而是我坚持的东西,可能是非常简单的,我有一本字典
NSArray *keys = [NSArray arrayWithObjects:@"1", @"2", nil];
NSArray *objects = [NSArray arrayWithObjects:@"3", @"4", nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
和didSelectRow我有
NSString *itemKey = [NSString stringWithFormat:@"%f", row];
survonemd.text = [dictionary objectForKey:itemKey];
这似乎确定
但我卡在titleForRow
任何帮助或提示将不胜感激。
我现在有 -
@property (nonatomic, retain) NSArray *keys;
@property (nonatomic, retain) NSArray *objects;
@synthesize keys;
@synthesize objects;
self.keys = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
self.objects = [NSArray arrayWithObjects:@"4", @"5", @"6", nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *itemKey = [keys objectAtIndex:row];
return [dictionary objectForKey:itemKey];
}
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *itemKey = [keys objectAtIndex:row];
survonemd.text = [dictionary objectForKey:itemKey];
}
它运行和选择器视图会从文本字段名为但没有数据显示在选择器。请帮忙。
提供一些代码可能会有帮助,但我会建议使用NSDictionary,因为它允许您有键和值。您可以将键显示在UIPickerView上,每个键对应于用户隐藏的值。 – Jumhyn 2010-12-10 08:10:44
感谢Jumhyn,我正在尝试使用字典,但我坚持的东西应该很简单。我有一本字典 – Mattog1456 2010-12-14 14:58:14