Objective c 用可变数组中的值填充选择器视图
我有两个按钮和两个可变数组。当我按下两个按钮中的一个时,我想用相应的数组填充Objective c 用可变数组中的值填充选择器视图,objective-c,uibutton,uipickerview,Objective C,Uibutton,Uipickerview,我有两个按钮和两个可变数组。当我按下两个按钮中的一个时,我想用相应的数组填充UIPickerView。但问题是,您只能实现一次选择器视图方法。所以现在我想检查按下了哪个按钮,然后用相应的数组填充我的选择器视图。有人有主意吗 -(IBAction)setPicker:(id)sender{ if (sender == btncategorie){ [self fillArrayCategorie]; } else { [self fillA
UIPickerView
。但问题是,您只能实现一次选择器视图方法。所以现在我想检查按下了哪个按钮,然后用相应的数组填充我的选择器视图。有人有主意吗
-(IBAction)setPicker:(id)sender{
if (sender == btncategorie){
[self fillArrayCategorie];
}
else {
[self fillArrayHomeparty];
}
if (pickview.hidden == TRUE) {
[pickview setHidden:NO];
[pickview reloadAllComponents];
}else {
[pickview setHidden:YES];
[pickview reloadAllComponents];
}
}
- (NSString *)pickerView:(UIPickerView *)pickview titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [arrayHomeParty objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[pickview setHidden:YES];
homLabel.text= [arrayHomeParty objectAtIndex:row];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickView{
return 1;// assuming a single spinning wheel of strings (not split into left/right for example)
}
-(NSInteger)pickerView:(UIPickerView *)pickview numberOfRowsInComponent:(NSInteger)component{
return [arrayHomeParty count];
}
这是我填充数组的代码。问题是我如何在我的pickerview方法中说,当按下homeparty按钮时,他们应该使用arrayHomeparty,当按下category按钮时,pickerviewer应该填充arrayCategorie。您可以制作一个反映数据状态的BOOL标志,或者只需使用
UISegmentedControl
在状态之间切换。在开关上重新加载选择器的数据,并在pickerView:titleForRow:
中返回与状态对应的标题。您可以制作一个反映数据状态的BOOL标志,或者只需使用UISegmentedControl
在状态之间切换。在开关上重新加载选择器的数据,并在pickerView:titleForRow:
中返回与状态对应的标题