1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.