我在一个项目中,我必须执行以下两项工作的工作填充UIPickerView: 1)从CoreData取值,并将其存储在一个的NSMutableArray。 2.)以UIPickerView并填充一个数组值。带有一个数组值
问题是阵列的大小是动态的,我很喜欢填充数组值UIPickerView。有人能帮我吗。
我在一个项目中,我必须执行以下两项工作的工作填充UIPickerView: 1)从CoreData取值,并将其存储在一个的NSMutableArray。 2.)以UIPickerView并填充一个数组值。带有一个数组值
问题是阵列的大小是动态的,我很喜欢填充数组值UIPickerView。有人能帮我吗。
为UIPickerView正常工作,你必须提供组件(列)的数量,每当它重新加载行每个组件的数量: 为使用[myPickerView reloadAllComponents];
在数组填充完成后重新加载视图,但在声明包含视图控制器类为<UIPickerViewDelegate>
之后,您必须也执行这些事情,将拾取器作为代理链接到文件所有者,然后:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;// or the number of vertical "columns" the picker will show...
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (myLoadedArray!=nil) {
return [myLoadedArray count];//this will tell the picker how many rows it has - in this case, the size of your loaded array...
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
//you can also write code here to descide what data to return depending on the component ("column")
if (myLoadedArray!=nil) {
return [myLoadedArray objectAtIndex:row];//assuming the array contains strings..
}
return @"";//or nil, depending how protective you are
}
不要忘记'UIPickerViewDataSource'协议 – 2016-12-11 14:38:07
更新数组中的值(插入或修改现有值)后。
致电reloadAllComponents
您的UIPickerView
实例。
- (void)reloadAllComponents
为了使用如下
[myPickerView reloadAllComponents];
什么是'UIPickercontroller'? – Jhaliya 2011-06-06 09:57:19
你到现在为止尝试过什么?你正在使用UIPickerView?你是否为它实现了委托方法? – 2011-06-06 10:02:28
@jhaliya UIPickercontroller用于显示数组值。 @Terente是的,我已经实现了它。 – Rahul 2011-06-06 10:05:40