使用可变数组中的值填充选择器视图

发布于 2024-12-29 05:15:33 字数 1329 浏览 3 评论 0原文

我有 2 个按钮和 2 个可变数组。当我按下两个按钮之一时,我想用相应的数组填充 UIPickerView 。但问题是你只能实现一次picker view 方法。所以现在我想检查按下了哪个按钮,然后用相应的数组填充我的选择器视图。有人有主意吗?

-(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,并且当按下类别按钮时,pickerviewer 应该填充 arrayCategorie。

I have 2 buttons and 2 mutable arrays. When I push one of the two buttons I want to fill up a UIPickerView with the corresponding array. But the problem is that you can only implement one time the picker view Methods. So now I want to check which button is pressed and then fill up my picker view with the corresponding array. Anyone got an idea?

-(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];
}

This is my code to fill up the arrays. The question is how I can say in my pickerview methods that they should use the arrayHomeparty when the homeparty button is pressed and that the pickerviewer should fill up with the arrayCategorie when the category button is pressed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉怎暖 2025-01-05 05:15:33

您可以创建一个反映数据状态的 BOOL 标志,或者仅使用 UISegmentedControl 在状态之间切换。在 switch 上重新加载选择器的数据,并在 pickerView:titleForRow: 中返回与状态相对应的标题。

You can make a BOOL flag which reflects the data state, or just use UISegmentedControl to switch between states. Reload your picker's data on switch and in the pickerView:titleForRow: return the title corresponding to state.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文