我有一个名为sectionNamesArray的NSMutableArray填充的UIPickerView。将项添加到sectionNamesArray时,如何手动调用此委托?
-- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return ([sectionNamesArray count] + 1);
}
问题是我将这个pickerView添加到titleView中navBar的中心。如果我试图取消UIPickerView并重新分配它以便希望再次调用该委托,则PickerView会显示在导航栏的左侧,而不是中心。我猜也许接口构建器设置在中心......?
以下是代码:
-(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];
}
答案 0 :(得分:4)
当您向阵列添加内容时,无法使用[UIPickerView reloadAllComponents]
或- (void)reloadComponent:(NSInteger)component
?
这很可能会查询您的委托并调用检查数组所需的所有内容并重新加载视图。