Kyle Parisi
Kyle Parisi

Reputation: 1416

UIPickerView not reloading until scrolling

Using a segment control I'm trying to reload 2 UIPickerViews with a new array of data.

My problem is the new array doesn't show until I scroll up or down on the picker (old data will go away once out of view). I've tried using the reloadAllComponents method to no luck. Here is what the code looks like:

//Segment Control
-(IBAction)unitType:(id)sender {
    if([sender selectedSegmentIndex]==0){
        NSLog(@"unitType change 1");
        NSLog(@"before values = %@",units);
        [units removeAllObjects];
        [units addObject:@"in"];
        //etc.
        [self.inputUnits reloadAllComponents];
        NSLog(@"current values = %@",units);
    }else {
        NSLog(@"unitType change 2");
        NSLog(@"before values = %@",units);
        [units removeAllObjects];
        [units addObject:@"in^3"];
        //etc.
        [self.inputUnits reloadAllComponents];
        NSLog(@"current values = %@",units);
    }
}

IB has 2 UIPickerViews wired up to the file's owner for both delegate and datasource.

Upvotes: 2

Views: 779

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

You haven't hooked up the UIPickerView to your inputUnits property. Thus, your call to -reloadAllComponents is getting sent to nil, and things are only getting updated when the pickerView wants to show something new (which it does when you scroll).

Upvotes: 5

Related Questions