Bryan
Bryan

Reputation: 17581

Update UIPickerView Number of Rows

I have a UIPickerView that is populated by an NSMutableArray called sectionNamesArray. When an item is added to sectionNamesArray, how do I manually get this delegate to be called?

-- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component

{

return ([sectionNamesArray count] + 1);

}

The problem is that I add this pickerView to the center of a navBar in the titleView. If I try to nil the UIPickerView and reallocate it in order to hopefully get the delegate called again, the PickerView shows up on the left side of the navbar, instead of the center. I am guessing maybe the interface builder settings got it in the center...?

Here's the code for that:

-(void) setupPickerView{
myPickerView = nil;
myPickerView = [[UIPickerView alloc] init];
myPickerView.backgroundColor = [UIColor clearColor];
myPickerView.delegate = self;
myPickerView.dataSource = self;
myPickerView.showsSelectionIndicator = YES;
[self.navigationController.navigationBar setBackgroundView:myPickerView];

CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero];
UIView *pickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(-40.0, -43.0, pickerSize.width, pickerSize.height)];
pickerTransformView.transform = CGAffineTransformMakeScale(.55f, .55f);

[pickerTransformView addSubview:myPickerView];
[self.navigationController.navigationBar setBackgroundView:pickerTransformView];

}

Upvotes: 0

Views: 3014

Answers (1)

mjdth
mjdth

Reputation: 6536

When you add something to your array can't you use [UIPickerView reloadAllComponents] or - (void)reloadComponent:(NSInteger)component?

That will most likely query your delegate and call everything necessary to check your array and reload the view.

Upvotes: 4

Related Questions